summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-03-06 13:41:02 +0100
committerEugene Burmako <xeno.by@gmail.com>2014-03-07 13:55:38 +0100
commiteb4a2e3343c9ee0ceaa249fc36b257dd6c13edf3 (patch)
treea0a36dc9289fae5f5b5955b905c44aae893ff7da
parent2dddb03b267770afcd0249ad700e55d53019e637 (diff)
downloadscala-eb4a2e3343c9ee0ceaa249fc36b257dd6c13edf3.tar.gz
scala-eb4a2e3343c9ee0ceaa249fc36b257dd6c13edf3.tar.bz2
scala-eb4a2e3343c9ee0ceaa249fc36b257dd6c13edf3.zip
SI-8364 fixes cxTree lookup for imports
This is reminiscent of the bug that I recently fixed in paradise: https://github.com/scalamacros/paradise/commit/0dc4e35883d357b7cbcdfd83b5b4821c1dcc0bb1. When doing something non-standard with contexts, we usually have to keep in mind that new contexts are created not only for trees that demarcate blocks of code, but also for imports.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala7
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala5
-rw-r--r--test/files/pos/t8364.check0
-rw-r--r--test/files/pos/t8364.scala12
4 files changed, 22 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 98ee4ad94d..133e80788b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -652,6 +652,13 @@ trait Contexts { self: Analyzer =>
c
}
+ def enclosingNonImportContext: Context = {
+ var c = this
+ while (c != NoContext && c.tree.isInstanceOf[Import])
+ c = c.outer
+ c
+ }
+
/** Is `sym` accessible as a member of `pre` in current context? */
def isAccessible(sym: Symbol, pre: Type, superAccess: Boolean = false): Boolean = {
lastAccessCheckDetails = ""
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2e1ed0863a..9f3f257529 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3946,7 +3946,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
* - simplest solution: have two method calls
*
*/
- def mkInvoke(cxTree: Tree, tree: Tree, qual: Tree, name: Name): Option[Tree] = {
+ def mkInvoke(context: Context, tree: Tree, qual: Tree, name: Name): Option[Tree] = {
+ val cxTree = context.enclosingNonImportContext.tree // SI-8364
debuglog(s"dyna.mkInvoke($cxTree, $tree, $qual, $name)")
val treeInfo.Applied(treeSelection, _, _) = tree
def isDesugaredApply = {
@@ -4608,7 +4609,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
t
}
def typedSelectInternal(tree: Tree, qual: Tree, name: Name): Tree = {
- def asDynamicCall = dyna.mkInvoke(context.tree, tree, qual, name) map { t =>
+ def asDynamicCall = dyna.mkInvoke(context, tree, qual, name) map { t =>
dyna.wrapErrors(t, (_.typed1(t, mode, pt)))
}
diff --git a/test/files/pos/t8364.check b/test/files/pos/t8364.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/pos/t8364.check
diff --git a/test/files/pos/t8364.scala b/test/files/pos/t8364.scala
new file mode 100644
index 0000000000..7a7ea1ff12
--- /dev/null
+++ b/test/files/pos/t8364.scala
@@ -0,0 +1,12 @@
+import scala.language.dynamics
+
+object MyDynamic extends Dynamic {
+ def selectDynamic(name: String): Any = ???
+}
+
+object Test extends App {
+ locally {
+ import java.lang.String
+ MyDynamic.id
+ }
+}