Skip to content

Commit 83d1883

Browse files
committed
Don't force info to get signature in TreeChecker
When we are reading a new definition from tasty and setting `info` of a symbol in `readNewDef`: sym.info = methodType(paramss, resType) The line above will reach `TreeChecker.transformSym`: assert(symd.signature == initial.signature At the time, the `symd` is not yet completed. Getting signature of the denotation will force the symbol and trigger completion of the info, which reaches the `PositionTree` in `readIndexedDef.
1 parent c54faa0 commit 83d1883

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

compiler/src/dotty/tools/dotc/core/NamerOps.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import ast.untpd
1111
/** Operations that are shared between Namer and TreeUnpickler */
1212
object NamerOps:
1313

14-
/** The given type, unless `sym` is a constructor, in which case the
15-
* type of the constructed instance is returned
14+
/** The type of the constructed instance is returned
15+
*
16+
* @param ctor the constructor
1617
*/
17-
def effectiveResultType(sym: Symbol, paramss: List[List[Symbol]], givenTp: Type)(using Context): Type =
18-
if sym.name == nme.CONSTRUCTOR then
19-
paramss match
20-
case TypeSymbols(tparams) :: _ => sym.owner.typeRef.appliedTo(tparams.map(_.typeRef))
21-
case _ => sym.owner.typeRef
22-
else givenTp
18+
def effectiveResultType(ctor: Symbol, paramss: List[List[Symbol]])(using Context): Type =
19+
paramss match
20+
case TypeSymbols(tparams) :: _ => ctor.owner.typeRef.appliedTo(tparams.map(_.typeRef))
21+
case _ => ctor.owner.typeRef
2322

2423
/** if isConstructor, make sure it has one leading non-implicit parameter list */
2524
def normalizeIfConstructor(paramss: List[List[Symbol]], isConstructor: Boolean)(using Context): List[List[Symbol]] =

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ class TreePickler(pickler: TastyPickler) {
332332

333333
def pickleDef(tag: Int, mdef: MemberDef, tpt: Tree, rhs: Tree = EmptyTree, pickleParams: => Unit = ())(using Context): Unit = {
334334
val sym = mdef.symbol
335+
335336
assert(symRefs(sym) == NoAddr, sym)
336337
registerDef(sym)
337338
writeByte(tag)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,11 @@ class TreeUnpickler(reader: TastyReader,
831831
val tpt = readTpt()(using localCtx)
832832
val paramss = normalizeIfConstructor(
833833
paramDefss.nestedMap(_.symbol), name == nme.CONSTRUCTOR)
834-
val resType = effectiveResultType(sym, paramss, tpt.tpe)
834+
val resType =
835+
if name == nme.CONSTRUCTOR then
836+
effectiveResultType(sym, paramss)
837+
else
838+
tpt.tpe
835839
sym.info = methodType(paramss, resType)
836840
DefDef(paramDefss, tpt)
837841
case VALDEF =>

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class TreeChecker extends Phase with SymTransformer {
9191
// until erasure, see the comment above `Compiler#phases`.
9292
if (ctx.phaseId <= erasurePhase.id) {
9393
val initial = symd.initial
94-
assert(symd.signature == initial.signature,
94+
assert(symd == initial || symd.signature == initial.signature,
9595
i"""Signature of ${sym.showLocated} changed at phase ${ctx.base.fusedContaining(ctx.phase.prev)}
9696
|Initial info: ${initial.info}
9797
|Initial sig : ${initial.signature}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ class Semantic {
795795

796796
// follow constructor
797797
if cls.hasSource then
798+
printer.println("init super class " + cls.show)
798799
val res2 = thisV.call(ctor, superType = NoType, source)(using heap, ctx, trace.add(source))
799800
errorBuffer ++= res2.errors
800801

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ class Namer { typer: Typer =>
16801680
if (isConstructor) {
16811681
// set result type tree to unit, but take the current class as result type of the symbol
16821682
typedAheadType(ddef.tpt, defn.UnitType)
1683-
wrapMethType(effectiveResultType(sym, paramSymss, NoType))
1683+
wrapMethType(effectiveResultType(sym, paramSymss))
16841684
}
16851685
else valOrDefDefSig(ddef, sym, paramSymss, wrapMethType)
16861686
}

0 commit comments

Comments
 (0)