@@ -977,10 +977,10 @@ class Semantic {
977
977
printer.println(acc.show + " initialized with " + value)
978
978
}
979
979
980
- // Handler is used to schedule super constructor calls.
980
+ // Tasks is used to schedule super constructor calls.
981
981
// Super constructor calls are delayed until all outers are set.
982
- type Handler = (( ) => Unit ) => Unit
983
- def superCall (tref : TypeRef , ctor : Symbol , args : List [ArgInfo ], source : Tree , handler : Handler )(using Env ): Unit =
982
+ type Tasks = mutable. ArrayBuffer [( ) => Unit ]
983
+ def superCall (tref : TypeRef , ctor : Symbol , args : List [ArgInfo ], source : Tree , tasks : Tasks )(using Env ): Unit =
984
984
val cls = tref.classSymbol.asClass
985
985
// update outer for super class
986
986
val res = outerValue(tref, thisV, klass, source)
@@ -989,28 +989,29 @@ class Semantic {
989
989
990
990
// follow constructor
991
991
if cls.hasSource then
992
- handler { () =>
992
+ tasks.append { () =>
993
993
printer.println(" init super class " + cls.show)
994
994
val res2 = thisV.call(ctor, args, superType = NoType , source)
995
995
errorBuffer ++= res2.errors
996
+ ()
996
997
}
997
998
998
999
// parents
999
- def initParent (parent : Tree , handler : Handler )(using Env ) = parent match {
1000
+ def initParent (parent : Tree , tasks : Tasks )(using Env ) = parent match {
1000
1001
case tree @ Block (stats, NewExpr (tref, New (tpt), ctor, argss)) => // can happen
1001
1002
eval(stats, thisV, klass).foreach { res => errorBuffer ++= res.errors }
1002
1003
val (errors, args) = evalArgs(argss.flatten, thisV, klass)
1003
1004
errorBuffer ++= errors
1004
- superCall(tref, ctor, args, tree, handler )
1005
+ superCall(tref, ctor, args, tree, tasks )
1005
1006
1006
1007
case tree @ NewExpr (tref, New (tpt), ctor, argss) => // extends A(args)
1007
1008
val (errors, args) = evalArgs(argss.flatten, thisV, klass)
1008
1009
errorBuffer ++= errors
1009
- superCall(tref, ctor, args, tree, handler )
1010
+ superCall(tref, ctor, args, tree, tasks )
1010
1011
1011
1012
case _ => // extends A or extends A[T]
1012
1013
val tref = typeRefOf(parent.tpe)
1013
- superCall(tref, tref.classSymbol.primaryConstructor, Nil , parent, handler )
1014
+ superCall(tref, tref.classSymbol.primaryConstructor, Nil , parent, tasks )
1014
1015
}
1015
1016
1016
1017
// see spec 5.1 about "Template Evaluation".
@@ -1020,13 +1021,12 @@ class Semantic {
1020
1021
1021
1022
// outers are set first
1022
1023
val tasks = new mutable.ArrayBuffer [() => Unit ]
1023
- val handler : Handler = task => tasks.append(task)
1024
1024
1025
1025
// 1. first init parent class recursively
1026
1026
// 2. initialize traits according to linearization order
1027
1027
val superParent = tpl.parents.head
1028
1028
val superCls = superParent.tpe.classSymbol.asClass
1029
- initParent(superParent, handler )
1029
+ initParent(superParent, tasks )
1030
1030
1031
1031
val parents = tpl.parents.tail
1032
1032
val mixins = klass.baseClasses.tail.takeWhile(_ != superCls)
@@ -1038,7 +1038,7 @@ class Semantic {
1038
1038
// calls and user code in the class body.
1039
1039
mixins.reverse.foreach { mixin =>
1040
1040
parents.find(_.tpe.classSymbol == mixin) match
1041
- case Some (parent) => initParent(parent, handler )
1041
+ case Some (parent) => initParent(parent, tasks )
1042
1042
case None =>
1043
1043
// According to the language spec, if the mixin trait requires
1044
1044
// arguments, then the class must provide arguments to it explicitly
@@ -1049,7 +1049,7 @@ class Semantic {
1049
1049
// term arguments to B. That can only be done in a concrete class.
1050
1050
val tref = typeRefOf(klass.typeRef.baseType(mixin).typeConstructor)
1051
1051
val ctor = tref.classSymbol.primaryConstructor
1052
- if ctor.exists then superCall(tref, ctor, Nil , superParent, handler )
1052
+ if ctor.exists then superCall(tref, ctor, Nil , superParent, tasks )
1053
1053
}
1054
1054
1055
1055
// initialize super classes after outers are set
0 commit comments