Skip to content

Commit cc86be4

Browse files
committed
Remove unnecessary context mode InSuperCall
After the previous commit, there was one usage of InSuperCall left in typedIdent to provide a better error message, but that usage can be replaced by a check to make sure we're in a secondary constructor instead, which means we can get rid of this mode avoid having to set and unset it in a bunch of places.
1 parent def1e35 commit cc86be4

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 => 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

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

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

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

10261026
private var localCtx: Context = _
10271027

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

Lines changed: 3 additions & 4 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.show), tree.sourcePos)
@@ -2191,7 +2190,7 @@ class Typer extends Namer
21912190
typer1.typedDefDef(tree, sym)(ctx.localContext(tree, sym).setTyper(typer1))
21922191
case tree: untpd.TypeDef =>
21932192
if (tree.isClassDef)
2194-
typedClassDef(tree, sym.asClass)(ctx.localContext(tree, sym).setMode(ctx.mode &~ Mode.InSuperCall))
2193+
typedClassDef(tree, sym.asClass)(ctx.localContext(tree, sym))
21952194
else
21962195
typedTypeDef(tree, sym)(ctx.localContext(tree, sym).setNewScope)
21972196
case tree: untpd.Labeled => typedLabeled(tree)

0 commit comments

Comments
 (0)