diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-03-13 09:35:37 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-03-13 09:43:25 +0100 |
commit | 0226345811636d05d67bbd574829df1515dff136 (patch) | |
tree | b19ab53015e1c2d80f4fd536af71a1dcfffb2fa2 | |
parent | 9c38e86a5526887f93a3f031b19a0e4fa31745d3 (diff) | |
download | scala-0226345811636d05d67bbd574829df1515dff136.tar.gz scala-0226345811636d05d67bbd574829df1515dff136.tar.bz2 scala-0226345811636d05d67bbd574829df1515dff136.zip |
SI-8403 Fix regression in name binding with imports in templates
Regressed in dbd8457 which changed `Context#make` to automatically
include the imports from the given `Tree` if it was an `Import`
tree, rather than requiring callers to call `makeNewImport`.
However, this turns out to double up the imports for the "inner" namer
of a template that starts with imports. The inner namer has a new
scope, but the same owner and tree as its parent.
This commit detects this case by seeing if the `Import` tree used
to consruct the child context is the same as the parent context.
If that is the case, we don't augment `Context#imports`.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t8403.scala | 9 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 133e80788b..994a2a4f4f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -433,8 +433,10 @@ trait Contexts { self: Analyzer => case _ => false } val isImport = tree match { - case _: Import => true - case _ => false + // The guard is for SI-8403. It prevents adding imports again in the context created by + // `Namer#createInnerNamer` + case _: Import if tree != this.tree => true + case _ => false } val sameOwner = owner == this.owner val prefixInChild = diff --git a/test/files/pos/t8403.scala b/test/files/pos/t8403.scala new file mode 100644 index 0000000000..eea60ed7ff --- /dev/null +++ b/test/files/pos/t8403.scala @@ -0,0 +1,9 @@ +trait Bug { + val u: { type Amb } = ??? + import u._ + + class Amb { def x = 0 } + class C(x: Amb) { // after dbd8457e4, "reference to Amb is ambiguous" + x.x + } +} |