diff options
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Mode.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 6 |
4 files changed, 15 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index ab6514507..f3e9fda74 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -154,7 +154,7 @@ object Checking { * by a `LazyRef`, or `ErrorType` if a cycle was detected and reported. */ def checkNonCyclic(sym: Symbol, info: Type, reportErrors: Boolean)(implicit ctx: Context): Type = { - val checker = new CheckNonCyclicMap(sym, reportErrors)(ctx.withMode(Mode.CheckCyclic)) + val checker = new CheckNonCyclicMap(sym, reportErrors)(ctx.addMode(Mode.CheckCyclic)) try checker.checkInfo(info) catch { case ex: CyclicReference => diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala index eb911987b..f855ef1c2 100644 --- a/src/dotty/tools/dotc/typer/Mode.scala +++ b/src/dotty/tools/dotc/typer/Mode.scala @@ -34,6 +34,8 @@ object Mode { val TypevarsMissContext = newMode(4, "TypevarsMissContext") val CheckCyclic = newMode(5, "CheckCyclic") + val InSuperCall = newMode(6, "InSuperCall") + /** This mode bit is set if we want to allow accessing a symbol's denotation * at a period before that symbol is first valid. An example where this is * the case is if we want to examine the environment where an access is made. @@ -44,7 +46,7 @@ object Mode { * before the symbol is defined will return the symbol's denotation at the * first phase where it is valid, instead of throwing a NotDefinedHere error. */ - val FutureDefsOK = newMode(6, "FutureDefsOK") + val FutureDefsOK = newMode(7, "FutureDefsOK") val PatternOrType = Pattern | Type }
\ No newline at end of file diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 782faf0d4..5ceab475e 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -200,7 +200,7 @@ class Namer { typer: Typer => } else completer - typr.println(i"creating symbol for $tree") + typr.println(i"creating symbol for $tree in ${ctx.mode}") def checkNoConflict(name: Name): Unit = { def preExisting = ctx.effectiveScope.lookup(name) @@ -213,12 +213,13 @@ class Namer { typer: Typer => } } + val inSuperCall = if (ctx.mode is Mode.InSuperCall) InSuperCall else EmptyFlags tree match { case tree: TypeDef if tree.isClassDef => val name = tree.name.encode.asTypeName checkNoConflict(name) val cls = record(ctx.newClassSymbol( - ctx.owner, name, tree.mods.flags, + ctx.owner, name, tree.mods.flags | inSuperCall, cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree), privateWithinClass(tree.mods), tree.pos, ctx.source.file)) cls.completer.asInstanceOf[ClassCompleter].init() @@ -229,6 +230,8 @@ class Namer { typer: Typer => val isDeferred = lacksDefinition(tree) val deferred = if (isDeferred) Deferred else EmptyFlags val method = if (tree.isInstanceOf[DefDef]) Method else EmptyFlags + val inSuperCall1 = if (tree.mods is ParamOrAccessor) EmptyFlags else inSuperCall + // suppress inSuperCall for constructor parameters val higherKinded = tree match { case tree: TypeDef if tree.tparams.nonEmpty && isDeferred => HigherKinded case _ => EmptyFlags @@ -243,7 +246,7 @@ class Namer { typer: Typer => val cctx = if (tree.name == nme.CONSTRUCTOR) ctx.outer else ctx record(ctx.newSymbol( - ctx.owner, name, tree.mods.flags | deferred | method | higherKinded, + ctx.owner, name, tree.mods.flags | deferred | method | higherKinded | inSuperCall1, adjustIfModule(new Completer(tree)(cctx), tree), privateWithinClass(tree.mods), tree.pos)) case tree: Import => @@ -428,7 +431,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) + protected implicit val ctx: Context = localContext(cls).setMode(ictx.mode &~ Mode.InSuperCall) val TypeDef(_, name, impl @ Template(constr, parents, self, body)) = original diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f58ccbdbc..9c5fb09b0 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -951,8 +951,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val typer1 = localTyper(sym) typer1.typedDefDef(tree, sym)(localContext(tree, sym).setTyper(typer1)) case tree: untpd.TypeDef => - if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext(tree, sym)) - else typedTypeDef(tree, sym)(localContext(tree, sym).setNewScope) + if (tree.isClassDef) + typedClassDef(tree, sym.asClass)(localContext(tree, sym).setMode(ctx.mode &~ Mode.InSuperCall)) + else + typedTypeDef(tree, sym)(localContext(tree, sym).setNewScope) case _ => typedUnadapted(desugar(tree), pt) } } |