Skip to content

Commit 31c1ac4

Browse files
committed
Simplify ByName handling in initialization checker
Since ByName nodes are now explicit, no need to introduce them separately in the checker.
1 parent 2066020 commit 31c1ac4

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,19 +1054,18 @@ object Semantic {
10541054
exprs.map { expr => eval(expr, thisV, klass) }
10551055

10561056
/** Evaluate arguments of methods */
1057-
def evalArgs(args: List[Arg], thisV: Ref, klass: ClassSymbol): Contextual[(List[Error], List[ArgInfo])] =
1057+
def evalArgs(args: List[Tree], thisV: Ref, klass: ClassSymbol): Contextual[(List[Error], List[ArgInfo])] =
10581058
val errors = new mutable.ArrayBuffer[Error]
10591059
val argInfos = new mutable.ArrayBuffer[ArgInfo]
10601060
args.foreach { arg =>
1061-
val res =
1062-
if arg.isByName then
1063-
val fun = Fun(arg.tree, thisV, klass, env)
1061+
val res = arg match
1062+
case ByName(expr) =>
1063+
val fun = Fun(expr, thisV, klass, env)
10641064
Result(fun, Nil)
1065-
else
1066-
eval(arg.tree, thisV, klass)
1067-
1065+
case _ =>
1066+
eval(arg, thisV, klass)
10681067
errors ++= res.errors
1069-
argInfos += ArgInfo(res.value, arg.tree)
1068+
argInfos += ArgInfo(res.value, arg)
10701069
}
10711070
(errors.toList, argInfos.toList)
10721071

@@ -1491,31 +1490,17 @@ object Semantic {
14911490
case hklambda: HKTypeLambda => typeRefOf(hklambda.resType)
14921491
}
14931492

1494-
opaque type Arg = Tree | ByNameArg // ^^^ can be simplified
1495-
case class ByNameArg(tree: Tree)
1496-
1497-
extension (arg: Arg)
1498-
def isByName = arg.isInstanceOf[ByNameArg]
1499-
def tree: Tree = arg match
1500-
case t: Tree => t
1501-
case ByNameArg(t) => t
1502-
15031493
object Call {
15041494

15051495
private def isDelayed(tp: Type)(using Context) =
15061496
tp.isInstanceOf[MethodicType] || tp.isByName
15071497

1508-
def unapply(tree: Tree)(using Context): Option[(Tree, List[List[Arg]])] =
1498+
def unapply(tree: Tree)(using Context): Option[(Tree, List[List[Tree]])] =
15091499
tree match
15101500
case Apply(fn, args) =>
1511-
val argTps = fn.tpe.widen match
1512-
case mt: MethodType => mt.paramInfos
1513-
val normArgs: List[Arg] = args.zip(argTps).map { (arg, formal) =>
1514-
if formal.isByName then ByNameArg(arg.dropByName) else arg
1515-
}
15161501
unapply(fn) match
1517-
case Some((ref, args0)) => Some((ref, args0 :+ normArgs))
1518-
case None => None
1502+
case Some((ref, args0)) => Some((ref, args0 :+ args))
1503+
case None => None
15191504

15201505
case TypeApply(fn, targs) =>
15211506
unapply(fn)
@@ -1527,7 +1512,7 @@ object Semantic {
15271512
}
15281513

15291514
object NewExpr {
1530-
def unapply(tree: Tree)(using Context): Option[(TypeRef, New, Symbol, List[List[Arg]])] =
1515+
def unapply(tree: Tree)(using Context): Option[(TypeRef, New, Symbol, List[List[Tree]])] =
15311516
tree match
15321517
case Call(fn @ Select(newTree: New, init), argss) if init == nme.CONSTRUCTOR =>
15331518
val tref = typeRefOf(newTree.tpe)

0 commit comments

Comments
 (0)