From b56a743edf1fe21ff1f9f070d17e4a23930e59bd Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 24 Aug 2014 18:51:26 +0200 Subject: Special context for self constructor args Arguments to this(...) calls need a special contet, similar to - but different from - the supercall context. --- src/dotty/tools/dotc/core/Contexts.scala | 13 +++++-------- src/dotty/tools/dotc/typer/Applications.scala | 6 ++++-- src/dotty/tools/dotc/typer/Mode.scala | 3 +-- 3 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src/dotty/tools/dotc') diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 5f0f6ee6a..b221d4083 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -267,7 +267,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 - * - as mode: inSuperCall * * The reasons for this peculiar choice of attributes are as follows: * @@ -283,7 +282,7 @@ object Contexts { */ def superCallContext: Context = { val locals = newScopeWith(owner.decls.filter(_ is ParamAccessor).toList: _*) - superOrThisCallContext(owner.primaryConstructor, locals)//.addMode(Mode.InSuperCall) + superOrThisCallContext(owner.primaryConstructor, locals) } /** The context for the arguments of a this(...) constructor call. @@ -293,20 +292,18 @@ object Contexts { * - as owner: The auxiliary constructor * - as outer context: The context enclosing the enclosing class context * - as scope: The parameters of the auxiliary constructor. - * - as mode: inSuperCall */ - def thisCallContext: Context = { + def thisCallArgContext: Context = { assert(owner.isClassConstructor) val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next var classCtx = outersIterator.dropWhile(!_.isClassDefContext).next - println(i"locals for this call: ${constrCtx.scope}") - classCtx.superOrThisCallContext(owner, constrCtx.scope) + classCtx.superOrThisCallContext(owner, constrCtx.scope).setTyperState(typerState) } /** The super= or this-call context with given owner and locals. */ - private def superOrThisCallContext(owner: Symbol, locals: Scope): Context = { + private def superOrThisCallContext(owner: Symbol, locals: Scope): FreshContext = { assert(isClassDefContext) - outer.fresh.setOwner(owner).setScope(locals)//.addMode(Mode.InSuperCall) + outer.fresh.setOwner(owner).setScope(locals) } /** The current source file; will be derived from current diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index a7c6a85cf..a126db1ad 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -445,7 +445,9 @@ trait Applications extends Compatibility { self: Typer => def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = { def realApply(implicit ctx: Context): Tree = track("realApply") { - var proto = new FunProto(tree.args, IgnoredProto(pt), this) + def argCtx(implicit ctx: Context) = + if (untpd.isSelfConstrCall(tree)) ctx.thisCallArgContext else ctx + var proto = new FunProto(tree.args, IgnoredProto(pt), this)(argCtx) val fun1 = typedExpr(tree.fun, proto) // Warning: The following line is dirty and fragile. We record that auto-tupling was demanded as @@ -461,7 +463,7 @@ trait Applications extends Compatibility { self: Typer => tryEither { implicit ctx => val app = if (proto.argsAreTyped) new ApplyToTyped(tree, fun1, funRef, proto.typedArgs, pt) - else new ApplyToUntyped(tree, fun1, funRef, proto, pt) + else new ApplyToUntyped(tree, fun1, funRef, proto, pt)(argCtx) val result = app.result ConstFold(result) } { (failedVal, failedState) => diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala index 54487722a..417d461e1 100644 --- a/src/dotty/tools/dotc/typer/Mode.scala +++ b/src/dotty/tools/dotc/typer/Mode.scala @@ -32,8 +32,7 @@ object Mode { val InferringReturnType = newMode(3, "InferringReturnType") val TypevarsMissContext = newMode(4, "TypevarsMissContext") - val InSuperCall = newMode(5, "InSuperCall") - val CheckCyclic = newMode(6, "CheckCyclic") + val CheckCyclic = newMode(5, "CheckCyclic") val PatternOrType = Pattern | Type } \ No newline at end of file -- cgit v1.2.3