Skip to content

Commit def1e35

Browse files
committed
Remove unnecessary parameter for typing Super
The `inConstrCall` parameter passed to `tpd.Super` and `assignType` should be true for super-calls to parent class constructors and false otherwise, this is used to correctly type the Super node: else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent.typeConstructor But calls to super-constructor are only generated by Mixin which runs after Erasure, so we can don't `inConstrCall` to take the correct branch. There were two places before erasure where we didn't just pass `inConstrCall = false` and they were both wrong: - In Typer, we had: case pt: SelectionProto if pt.name == nme.CONSTRUCTOR => true But Typer never generates super-calls to constructors (such calls are just regular constructor calls in the extends clause until Mixin) - In TreeUnpickler, we had: ctx.mode.is(Mode.InSuperCall) Which doesn't really make sense (it checks whether the super-call is happening inside the extends clause or a secondary constructor)
1 parent 30f8c6f commit def1e35

File tree

9 files changed

+14
-18
lines changed

9 files changed

+14
-18
lines changed

compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class JUnitBootstrappers extends MiniPhase {
181181
val sym = ctx.newDefaultConstructor(owner).entered
182182
DefDef(sym, {
183183
Block(
184-
Super(This(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil,
184+
Super(This(owner), tpnme.EMPTY).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil,
185185
unitLiteral
186186
)
187187
})

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
3535
def This(cls: ClassSymbol)(implicit ctx: Context): This =
3636
untpd.This(untpd.Ident(cls.name)).withType(cls.thisType)
3737

38-
def Super(qual: Tree, mix: untpd.Ident, inConstrCall: Boolean, mixinClass: Symbol)(implicit ctx: Context): Super =
39-
ta.assignType(untpd.Super(qual, mix), qual, inConstrCall, mixinClass)
38+
def Super(qual: Tree, mix: untpd.Ident, mixinClass: Symbol)(implicit ctx: Context): Super =
39+
ta.assignType(untpd.Super(qual, mix), qual, mixinClass)
4040

41-
def Super(qual: Tree, mixName: TypeName, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super =
42-
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), inConstrCall, mixinClass)
41+
def Super(qual: Tree, mixName: TypeName, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super =
42+
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), mixinClass)
4343

4444
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
4545
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]] || fn.isInstanceOf[Inlined])

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ class TreeUnpickler(reader: TastyReader,
10981098
case SUPER =>
10991099
val qual = readTerm()
11001100
val (mixId, mixTpe) = ifBefore(end)(readQualId(), (untpd.EmptyTypeIdent, NoType))
1101-
tpd.Super(qual, mixId, ctx.mode.is(Mode.InSuperCall), mixTpe.typeSymbol)
1101+
tpd.Super(qual, mixId, mixTpe.typeSymbol)
11021102
case APPLY =>
11031103
val fn = readTerm()
11041104
tpd.Apply(fn, until(end)(readTerm()))

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11921192
setSym()
11931193
val qual = readTreeRef()
11941194
val mix = readTypeNameRef()
1195-
Super(qual, mix, inConstrCall = false) // todo: revise
1195+
Super(qual, mix)
11961196

11971197
case THIStree =>
11981198
setSym()

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
477477
def Super_id(self: Super)(using ctx: Context): Option[Id] = optional(self.mix)
478478

479479
def Super_apply(qual: Term, mix: Option[Id])(using ctx: Context): Super =
480-
withDefaultPos(tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), false, NoSymbol))
480+
withDefaultPos(tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), NoSymbol))
481481

482482
def Super_copy(original: Tree)(qual: Term, mix: Option[Id])(using ctx: Context): Super =
483483
tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
3030

3131
def superRef(target: Symbol, span: Span = cls.span): Tree = {
3232
val sup = if (target.isConstructor && !target.owner.is(Trait))
33-
Super(This(cls), tpnme.EMPTY, true)
33+
Super(This(cls), tpnme.EMPTY)
3434
else
35-
Super(This(cls), target.owner.name.asTypeName, false, target.owner)
35+
Super(This(cls), target.owner.name.asTypeName, target.owner)
3636
//println(i"super ref $target on $sup")
3737
ast.untpd.Select(sup.withSpan(span), target.name)
3838
.withType(NamedType(sup.tpe, target))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ParamForwarding extends MiniPhase with IdentityDenotTransformer:
6464
info = sym.info.ensureMethodic
6565
).installAfter(thisPhase)
6666
val superAcc =
67-
Super(This(currentClass), tpnme.EMPTY, inConstrCall = false)
67+
Super(This(currentClass), tpnme.EMPTY)
6868
.withSpan(mdef.span)
6969
.select(alias)
7070
.ensureApplied

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ trait TypeAssigner {
369369
else errorType("not a legal qualifying class for this", tree.sourcePos))
370370
}
371371

372-
def assignType(tree: untpd.Super, qual: Tree, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = {
372+
def assignType(tree: untpd.Super, qual: Tree, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = {
373373
val mix = tree.mix
374374
qual.tpe match {
375375
case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err)
@@ -386,7 +386,7 @@ trait TypeAssigner {
386386
val owntype =
387387
if (mixinClass.exists) mixinClass.appliedRef
388388
else if (!mix.isEmpty) findMixinSuper(cls.info)
389-
else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent.typeConstructor
389+
else if (ctx.erasedTypes) cls.info.firstParent.typeConstructor
390390
else {
391391
val ps = cls.classInfo.parents
392392
if (ps.isEmpty) defn.AnyType else ps.reduceLeft((x: Type, y: Type) => x & y)

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,14 @@ class Typer extends Namer
539539

540540
def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree = {
541541
val qual1 = typed(tree.qual)
542-
val inConstrCall = pt match {
543-
case pt: SelectionProto if pt.name == nme.CONSTRUCTOR => true
544-
case _ => false
545-
}
546542
val enclosingInlineable = ctx.owner.ownersIterator.findSymbol(_.isInlineMethod)
547543
if (enclosingInlineable.exists && !PrepareInlineable.isLocal(qual1.symbol, enclosingInlineable))
548544
ctx.error(SuperCallsNotAllowedInlineable(enclosingInlineable), tree.sourcePos)
549545
pt match {
550546
case pt: SelectionProto if pt.name.isTypeName =>
551547
qual1 // don't do super references for types; they are meaningless anyway
552548
case _ =>
553-
assignType(cpy.Super(tree)(qual1, tree.mix), qual1, inConstrCall)
549+
assignType(cpy.Super(tree)(qual1, tree.mix), qual1)
554550
}
555551
}
556552

0 commit comments

Comments
 (0)