diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 5 | ||||
-rw-r--r-- | test/files/pos/t8364.check | 0 | ||||
-rw-r--r-- | test/files/pos/t8364.scala | 12 |
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 + } +} |