diff --git a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala index 4f58c619b438..f192b33d830b 100644 --- a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala +++ b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala @@ -181,7 +181,7 @@ class JUnitBootstrappers extends MiniPhase { val sym = ctx.newDefaultConstructor(owner).entered DefDef(sym, { Block( - Super(This(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil, + Super(This(owner), tpnme.EMPTY).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil, unitLiteral ) }) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 7ad6424682ea..3f68e186b241 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -35,11 +35,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def This(cls: ClassSymbol)(implicit ctx: Context): This = untpd.This(untpd.Ident(cls.name)).withType(cls.thisType) - def Super(qual: Tree, mix: untpd.Ident, inConstrCall: Boolean, mixinClass: Symbol)(implicit ctx: Context): Super = - ta.assignType(untpd.Super(qual, mix), qual, inConstrCall, mixinClass) + def Super(qual: Tree, mix: untpd.Ident, mixinClass: Symbol)(implicit ctx: Context): Super = + ta.assignType(untpd.Super(qual, mix), qual, mixinClass) - def Super(qual: Tree, mixName: TypeName, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = - Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), inConstrCall, mixinClass) + def Super(qual: Tree, mixName: TypeName, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = + Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), mixinClass) def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = { assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]] || fn.isInstanceOf[Inlined]) diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 92a6eee9b285..b4229f6a86c8 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -353,7 +353,6 @@ object Contexts { * - as owner: The primary constructor of the class * - as outer context: The context enclosing the class context * - as scope: The parameter accessors in the class context - * - with additional mode: InSuperCall * * The reasons for this peculiar choice of attributes are as follows: * @@ -394,7 +393,7 @@ object Contexts { var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next() classCtx.outer.fresh.setOwner(owner) .setScope(locals) - .setMode(classCtx.mode | Mode.InSuperCall) + .setMode(classCtx.mode) } /** The context of expression `expr` seen as a member of a statement sequence */ diff --git a/compiler/src/dotty/tools/dotc/core/Mode.scala b/compiler/src/dotty/tools/dotc/core/Mode.scala index de07aa242c95..860e87386b8d 100644 --- a/compiler/src/dotty/tools/dotc/core/Mode.scala +++ b/compiler/src/dotty/tools/dotc/core/Mode.scala @@ -43,9 +43,6 @@ object Mode { val CheckCyclic: Mode = newMode(5, "CheckCyclic") - /** We are looking at the arguments of a supercall */ - val InSuperCall: Mode = newMode(6, "InSuperCall") - /** We are in a pattern alternative */ val InPatternAlternative: Mode = newMode(7, "InPatternAlternative") diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index e4f2772ed960..fabf20b49418 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -670,7 +670,7 @@ class TreeUnpickler(reader: TastyReader, readByte() val end = readEnd() val tp = readType() - val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx)) + val lazyAnnotTree = readLaterWithOwner(end, rdr => implicit ctx => rdr.readTerm()) owner => Annotation.deferredSymAndTree(tp.typeSymbol)(lazyAnnotTree(owner).complete) @@ -780,7 +780,7 @@ class TreeUnpickler(reader: TastyReader, def complete(implicit ctx: Context) = typer.Inliner.bodyToInline(sym) } else - readLater(end, rdr => ctx => rdr.readTerm()(ctx.retractMode(Mode.InSuperCall))) + readLater(end, rdr => implicit ctx => rdr.readTerm()) def ValDef(tpt: Tree) = ta.assignType(untpd.ValDef(sym.name.asTermName, tpt, readRhs(localCtx)), sym) @@ -1032,9 +1032,7 @@ class TreeUnpickler(reader: TastyReader, } def completeSelect(name: Name, sig: Signature): Select = { - val localCtx = - if (name == nme.CONSTRUCTOR) ctx.addMode(Mode.InSuperCall) else ctx - val qual = readTerm()(localCtx) + val qual = readTerm()(ctx) var qualType = qual.tpe.widenIfUnstable val denot = accessibleDenot(qualType, name, sig) val owner = denot.symbol.maybeOwner @@ -1098,7 +1096,7 @@ class TreeUnpickler(reader: TastyReader, case SUPER => val qual = readTerm() val (mixId, mixTpe) = ifBefore(end)(readQualId(), (untpd.EmptyTypeIdent, NoType)) - tpd.Super(qual, mixId, ctx.mode.is(Mode.InSuperCall), mixTpe.typeSymbol) + tpd.Super(qual, mixId, mixTpe.typeSymbol) case APPLY => val fn = readTerm() tpd.Apply(fn, until(end)(readTerm())) diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 13524342e6ad..a644fbaad5e3 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -1192,7 +1192,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas setSym() val qual = readTreeRef() val mix = readTypeNameRef() - Super(qual, mix, inConstrCall = false) // todo: revise + Super(qual, mix) case THIStree => setSym() diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index f4cc413c5367..a9ed627c0750 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -477,7 +477,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def Super_id(self: Super)(using ctx: Context): Option[Id] = optional(self.mix) def Super_apply(qual: Term, mix: Option[Id])(using ctx: Context): Super = - withDefaultPos(tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), false, NoSymbol)) + withDefaultPos(tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), NoSymbol)) def Super_copy(original: Tree)(qual: Term, mix: Option[Id])(using ctx: Context): Super = tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) diff --git a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala index 62338d744b5c..784a21ba248d 100644 --- a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala @@ -30,9 +30,9 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont def superRef(target: Symbol, span: Span = cls.span): Tree = { val sup = if (target.isConstructor && !target.owner.is(Trait)) - Super(This(cls), tpnme.EMPTY, true) + Super(This(cls), tpnme.EMPTY) else - Super(This(cls), target.owner.name.asTypeName, false, target.owner) + Super(This(cls), target.owner.name.asTypeName, target.owner) //println(i"super ref $target on $sup") ast.untpd.Select(sup.withSpan(span), target.name) .withType(NamedType(sup.tpe, target)) diff --git a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index fbbb233a89d7..49d1e5d42883 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -64,7 +64,7 @@ class ParamForwarding extends MiniPhase with IdentityDenotTransformer: info = sym.info.ensureMethodic ).installAfter(thisPhase) val superAcc = - Super(This(currentClass), tpnme.EMPTY, inConstrCall = false) + Super(This(currentClass), tpnme.EMPTY) .withSpan(mdef.span) .select(alias) .ensureApplied diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 0f74dbc456bc..a111e60eb5d1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1021,7 +1021,7 @@ class Namer { typer: Typer => class ClassCompleter(cls: ClassSymbol, original: TypeDef)(ictx: Context) extends Completer(original)(ictx) { withDecls(newScope) - protected implicit val ctx: Context = localContext(cls).setMode(ictx.mode &~ Mode.InSuperCall) + protected implicit val ctx: Context = localContext(cls) private var localCtx: Context = _ diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index f6d4259fdb6b..e632279f9609 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -369,7 +369,7 @@ trait TypeAssigner { else errorType("not a legal qualifying class for this", tree.sourcePos)) } - def assignType(tree: untpd.Super, qual: Tree, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = { + def assignType(tree: untpd.Super, qual: Tree, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super = { val mix = tree.mix qual.tpe match { case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err) @@ -386,7 +386,7 @@ trait TypeAssigner { val owntype = if (mixinClass.exists) mixinClass.appliedRef else if (!mix.isEmpty) findMixinSuper(cls.info) - else if (inConstrCall || ctx.erasedTypes) cls.info.firstParent.typeConstructor + else if (ctx.erasedTypes) cls.info.firstParent.typeConstructor else { val ps = cls.classInfo.parents if (ps.isEmpty) defn.AnyType else ps.reduceLeft((x: Type, y: Type) => x & y) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 0968c7881317..e7b44a07afa8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -445,10 +445,9 @@ class Typer extends Namer return ref(defn.XMLTopScopeModule.termRef) else if (name.toTermName == nme.ERROR) UnspecifiedErrorType - else if (ctx.owner.isConstructor && ctx.mode.is(Mode.InSuperCall) && + else if (ctx.owner.isConstructor && !ctx.owner.isPrimaryConstructor && ctx.owner.owner.unforcedDecls.lookup(tree.name).exists) - // When InSuperCall mode and in a constructor we are in the arguments - // of a this(...) constructor call + // we are in the arguments of a this(...) constructor call errorType(ex"$tree is not accessible from constructor arguments", tree.sourcePos) else errorType(new MissingIdent(tree, kind, name.show), tree.sourcePos) @@ -539,10 +538,6 @@ class Typer extends Namer def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree = { val qual1 = typed(tree.qual) - val inConstrCall = pt match { - case pt: SelectionProto if pt.name == nme.CONSTRUCTOR => true - case _ => false - } val enclosingInlineable = ctx.owner.ownersIterator.findSymbol(_.isInlineMethod) if (enclosingInlineable.exists && !PrepareInlineable.isLocal(qual1.symbol, enclosingInlineable)) ctx.error(SuperCallsNotAllowedInlineable(enclosingInlineable), tree.sourcePos) @@ -550,7 +545,7 @@ class Typer extends Namer case pt: SelectionProto if pt.name.isTypeName => qual1 // don't do super references for types; they are meaningless anyway case _ => - assignType(cpy.Super(tree)(qual1, tree.mix), qual1, inConstrCall) + assignType(cpy.Super(tree)(qual1, tree.mix), qual1) } } @@ -2195,7 +2190,7 @@ class Typer extends Namer typer1.typedDefDef(tree, sym)(ctx.localContext(tree, sym).setTyper(typer1)) case tree: untpd.TypeDef => if (tree.isClassDef) - typedClassDef(tree, sym.asClass)(ctx.localContext(tree, sym).setMode(ctx.mode &~ Mode.InSuperCall)) + typedClassDef(tree, sym.asClass)(ctx.localContext(tree, sym)) else typedTypeDef(tree, sym)(ctx.localContext(tree, sym).setNewScope) case tree: untpd.Labeled => typedLabeled(tree)