Skip to content

Commit ac9ef34

Browse files
committed
Handle callConstructor
1 parent 1146598 commit ac9ef34

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ object Semantic {
140140
def hasField(f: Symbol) = fields.contains(f)
141141
}
142142

143-
/** Abstract heap stores abstract warm objects
143+
/** Abstract heap stores abstract objects
144144
*
145145
* The heap serves as cache of summaries for warm objects and is shared for checking all classes.
146+
*
147+
* The fact that objects of `ThisRef` are stored in heap is just an engineering convenience.
148+
* Technically, we can also store the object directly in `ThisRef`.
146149
*/
147150
object Heap {
148151
class Heap(private var map: Map[Ref, Objekt]) {
@@ -322,6 +325,9 @@ object Semantic {
322325
def call(meth: Symbol, args: List[ArgInfo], superType: Type, source: Tree): Contextual[Result] =
323326
value.call(meth, args, superType, source) ++ errors
324327

328+
def callConstructor(ctor: Symbol, args: List[ArgInfo], source: Tree): Contextual[Result] =
329+
value.callConstructor(ctor, args, source) ++ errors
330+
325331
def instantiate(klass: ClassSymbol, ctor: Symbol, args: List[ArgInfo], source: Tree): Contextual[Result] =
326332
value.instantiate(klass, ctor, args, source) ++ errors
327333
}
@@ -934,7 +940,10 @@ object Semantic {
934940

935941
case Select(qual, _) =>
936942
val res = eval(qual, thisV, klass) ++ errors
937-
res.call(ref.symbol, args, superType = NoType, source = expr)
943+
if ref.symbol.isConstructor then
944+
res.callConstructor(ref.symbol, args, source = expr)
945+
else
946+
res.call(ref.symbol, args, superType = NoType, source = expr)
938947

939948
case id: Ident =>
940949
id.tpe match
@@ -946,7 +955,10 @@ object Semantic {
946955
thisValue2.call(id.symbol, args, superType = NoType, expr, needResolve = false)
947956
case TermRef(prefix, _) =>
948957
val res = cases(prefix, thisV, klass, id) ++ errors
949-
res.call(id.symbol, args, superType = NoType, source = expr)
958+
if id.symbol.isConstructor then
959+
res.callConstructor(id.symbol, args, source = expr)
960+
else
961+
res.call(id.symbol, args, superType = NoType, source = expr)
950962

951963
case Select(qualifier, name) =>
952964
val qualRes = eval(qualifier, thisV, klass)

0 commit comments

Comments
 (0)