diff options
author | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-10 11:38:55 -0700 |
---|---|---|
committer | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-10 11:38:55 -0700 |
commit | ca23e50d2df14ce999c657a5f3cf79e5ffb6a450 (patch) | |
tree | 3ef98f240def1be8f4f170a25dba22ce61f84786 | |
parent | 782f362e0bcaa9609ed1a1c23c313257d0e22632 (diff) | |
parent | 73cb55a80dc65577e593f59a16098cf915527a1d (diff) | |
download | scala-ca23e50d2df14ce999c657a5f3cf79e5ffb6a450.tar.gz scala-ca23e50d2df14ce999c657a5f3cf79e5ffb6a450.tar.bz2 scala-ca23e50d2df14ce999c657a5f3cf79e5ffb6a450.zip |
Merge pull request #1270 from paulp/issue/6327
Fix for SI-6327, wrongness in Dynamic.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 20 | ||||
-rw-r--r-- | test/files/run/t6327.check | 4 | ||||
-rw-r--r-- | test/files/run/t6327.scala | 22 |
3 files changed, 39 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index d055c6ec48..a224c546e4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3817,18 +3817,23 @@ trait Typers extends Modes with Adaptations with Tags { * - simplest solution: have two method calls * */ - def mkInvoke(cxTree: Tree, tree: Tree, qual: Tree, name: Name): Option[Tree] = + def mkInvoke(cxTree: Tree, tree: Tree, qual: Tree, name: Name): Option[Tree] = { + debuglog(s"mkInvoke($cxTree, $tree, $qual, $name)") acceptsApplyDynamicWithType(qual, name) map { tp => // tp eq NoType => can call xxxDynamic, but not passing any type args (unless specified explicitly by the user) // in scala-virtualized, when not NoType, tp is passed as type argument (for selection on a staged Struct) - // strip off type application -- we're not doing much with outer, so don't bother preserving cxTree's attributes etc - val (outer, explicitTargs) = cxTree match { - case TypeApply(fun, targs) => (fun, targs) - case Apply(TypeApply(fun, targs), args) => (Apply(fun, args), targs) - case t => (t, Nil) + // strip off type application -- we're not doing much with outer, + // so don't bother preserving cxTree's attributes etc + val cxTree1 = cxTree match { + case t: ValOrDefDef => t.rhs + case t => t + } + val (outer, explicitTargs) = cxTree1 match { + case TypeApply(fun, targs) => (fun, targs) + case Apply(TypeApply(fun, targs), args) => (Apply(fun, args), targs) + case t => (t, Nil) } - @inline def hasNamedArg(as: List[Tree]) = as.collectFirst{case AssignOrNamedArg(lhs, rhs) =>}.nonEmpty // note: context.tree includes at most one Apply node @@ -3853,6 +3858,7 @@ trait Typers extends Modes with Adaptations with Tags { atPos(qual.pos)(Apply(tappSel, List(Literal(Constant(name.decode))))) } + } } @inline final def deindentTyping() = context.typingIndentLevel -= 2 diff --git a/test/files/run/t6327.check b/test/files/run/t6327.check new file mode 100644 index 0000000000..f7bacac931 --- /dev/null +++ b/test/files/run/t6327.check @@ -0,0 +1,4 @@ +A +A +A +A diff --git a/test/files/run/t6327.scala b/test/files/run/t6327.scala new file mode 100644 index 0000000000..7683101f14 --- /dev/null +++ b/test/files/run/t6327.scala @@ -0,0 +1,22 @@ +import language._ + +object Test extends App { + + case class R[+T](s: String) { def x() = println(s) } + + // Implicits in contention; StringR is nested to avoid ambiguity + object R { implicit val StringR = R[String]("A") } + implicit val Default = R[Any]("B") + + class B() extends Dynamic { + def selectDynamic[T](f: String)(implicit r: R[T]): Unit = r.x() + } + + val b = new B() + + // These should all produce the same output, but they don't + b.selectDynamic[String]("baz") + b.baz[String] + val c = b.selectDynamic[String]("baz") + val d = b.baz[String] +} |