Skip to content

Commit 42932dc

Browse files
authored
Merge pull request #8591 from dotty-staging/try/super-constr-call
Simplify super call handling: remove inConstrCall, remove InSuperCall
2 parents 4581490 + c94c58e commit 42932dc

File tree

12 files changed

+22
-33
lines changed

12 files changed

+22
-33
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/Contexts.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ object Contexts {
353353
* - as owner: The primary constructor of the class
354354
* - as outer context: The context enclosing the class context
355355
* - as scope: The parameter accessors in the class context
356-
* - with additional mode: InSuperCall
357356
*
358357
* The reasons for this peculiar choice of attributes are as follows:
359358
*
@@ -394,7 +393,7 @@ object Contexts {
394393
var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next()
395394
classCtx.outer.fresh.setOwner(owner)
396395
.setScope(locals)
397-
.setMode(classCtx.mode | Mode.InSuperCall)
396+
.setMode(classCtx.mode)
398397
}
399398

400399
/** The context of expression `expr` seen as a member of a statement sequence */

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ object Mode {
4343

4444
val CheckCyclic: Mode = newMode(5, "CheckCyclic")
4545

46-
/** We are looking at the arguments of a supercall */
47-
val InSuperCall: Mode = newMode(6, "InSuperCall")
48-
4946
/** We are in a pattern alternative */
5047
val InPatternAlternative: Mode = newMode(7, "InPatternAlternative")
5148

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ class TreeUnpickler(reader: TastyReader,
670670
readByte()
671671
val end = readEnd()
672672
val tp = readType()
673-
val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx))
673+
val lazyAnnotTree = readLaterWithOwner(end, rdr => implicit ctx => rdr.readTerm())
674674

675675
owner =>
676676
Annotation.deferredSymAndTree(tp.typeSymbol)(lazyAnnotTree(owner).complete)
@@ -780,7 +780,7 @@ class TreeUnpickler(reader: TastyReader,
780780
def complete(implicit ctx: Context) = typer.Inliner.bodyToInline(sym)
781781
}
782782
else
783-
readLater(end, rdr => ctx => rdr.readTerm()(ctx.retractMode(Mode.InSuperCall)))
783+
readLater(end, rdr => implicit ctx => rdr.readTerm())
784784

785785
def ValDef(tpt: Tree) =
786786
ta.assignType(untpd.ValDef(sym.name.asTermName, tpt, readRhs(localCtx)), sym)
@@ -1032,9 +1032,7 @@ class TreeUnpickler(reader: TastyReader,
10321032
}
10331033

10341034
def completeSelect(name: Name, sig: Signature): Select = {
1035-
val localCtx =
1036-
if (name == nme.CONSTRUCTOR) ctx.addMode(Mode.InSuperCall) else ctx
1037-
val qual = readTerm()(localCtx)
1035+
val qual = readTerm()(ctx)
10381036
var qualType = qual.tpe.widenIfUnstable
10391037
val denot = accessibleDenot(qualType, name, sig)
10401038
val owner = denot.symbol.maybeOwner
@@ -1098,7 +1096,7 @@ class TreeUnpickler(reader: TastyReader,
10981096
case SUPER =>
10991097
val qual = readTerm()
11001098
val (mixId, mixTpe) = ifBefore(end)(readQualId(), (untpd.EmptyTypeIdent, NoType))
1101-
tpd.Super(qual, mixId, ctx.mode.is(Mode.InSuperCall), mixTpe.typeSymbol)
1099+
tpd.Super(qual, mixId, mixTpe.typeSymbol)
11021100
case APPLY =>
11031101
val fn = readTerm()
11041102
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/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ class Namer { typer: Typer =>
10271027
class ClassCompleter(cls: ClassSymbol, original: TypeDef)(ictx: Context) extends Completer(original)(ictx) {
10281028
withDecls(newScope)
10291029

1030-
protected implicit val ctx: Context = localContext(cls).setMode(ictx.mode &~ Mode.InSuperCall)
1030+
protected implicit val ctx: Context = localContext(cls)
10311031

10321032
private var localCtx: Context = _
10331033

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: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,9 @@ class Typer extends Namer
445445
return ref(defn.XMLTopScopeModule.termRef)
446446
else if (name.toTermName == nme.ERROR)
447447
UnspecifiedErrorType
448-
else if (ctx.owner.isConstructor && ctx.mode.is(Mode.InSuperCall) &&
448+
else if (ctx.owner.isConstructor && !ctx.owner.isPrimaryConstructor &&
449449
ctx.owner.owner.unforcedDecls.lookup(tree.name).exists)
450-
// When InSuperCall mode and in a constructor we are in the arguments
451-
// of a this(...) constructor call
450+
// we are in the arguments of a this(...) constructor call
452451
errorType(ex"$tree is not accessible from constructor arguments", tree.sourcePos)
453452
else
454453
errorType(new MissingIdent(tree, kind, name), tree.sourcePos)
@@ -539,18 +538,14 @@ class Typer extends Namer
539538

540539
def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree = {
541540
val qual1 = typed(tree.qual)
542-
val inConstrCall = pt match {
543-
case pt: SelectionProto if pt.name == nme.CONSTRUCTOR => true
544-
case _ => false
545-
}
546541
val enclosingInlineable = ctx.owner.ownersIterator.findSymbol(_.isInlineMethod)
547542
if (enclosingInlineable.exists && !PrepareInlineable.isLocal(qual1.symbol, enclosingInlineable))
548543
ctx.error(SuperCallsNotAllowedInlineable(enclosingInlineable), tree.sourcePos)
549544
pt match {
550545
case pt: SelectionProto if pt.name.isTypeName =>
551546
qual1 // don't do super references for types; they are meaningless anyway
552547
case _ =>
553-
assignType(cpy.Super(tree)(qual1, tree.mix), qual1, inConstrCall)
548+
assignType(cpy.Super(tree)(qual1, tree.mix), qual1)
554549
}
555550
}
556551

@@ -2195,7 +2190,7 @@ class Typer extends Namer
21952190
typer1.typedDefDef(tree, sym)(ctx.localContext(tree, sym).setTyper(typer1))
21962191
case tree: untpd.TypeDef =>
21972192
if (tree.isClassDef)
2198-
typedClassDef(tree, sym.asClass)(ctx.localContext(tree, sym).setMode(ctx.mode &~ Mode.InSuperCall))
2193+
typedClassDef(tree, sym.asClass)(ctx.localContext(tree, sym))
21992194
else
22002195
typedTypeDef(tree, sym)(ctx.localContext(tree, sym).setNewScope)
22012196
case tree: untpd.Labeled => typedLabeled(tree)

0 commit comments

Comments
 (0)