Skip to content

Commit

Permalink
SI-8004 Resolve NoPosition error for applyDynamicNamed method call
Browse files Browse the repository at this point in the history
Previously, there were no positions created for the tuples that are
generated while doing the transformation for an applyDynamicNamed call.
This led to an NoPosition error in scalac when one tries to show
position information in the AST. Furthermore, this simplifies semantic
highlighting in the scala-ide because no position information for color
ranges have to be created anymore.
  • Loading branch information
kiritsuku authored and retronym committed Nov 26, 2013
1 parent b915f44 commit 696545d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -3999,9 +3999,14 @@ trait Typers extends Modes with Adaptations with Tags {


def typedNamedApply(orig: Tree, fun: Tree, args: List[Tree], mode: Int, pt: Type): Tree = { def typedNamedApply(orig: Tree, fun: Tree, args: List[Tree], mode: Int, pt: Type): Tree = {
def argToBinding(arg: Tree): Tree = arg match { def argToBinding(arg: Tree): Tree = arg match {
case AssignOrNamedArg(Ident(name), rhs) => gen.mkTuple(List(CODE.LIT(name.toString), rhs)) case AssignOrNamedArg(i @ Ident(name), rhs) =>
case _ => gen.mkTuple(List(CODE.LIT(""), arg)) atPos(i.pos.withEnd(rhs.pos.endOrPoint)) {
gen.mkTuple(List(atPos(i.pos)(CODE.LIT(name.toString)), rhs))
}
case _ =>
gen.mkTuple(List(CODE.LIT(""), arg))
} }

val t = treeCopy.Apply(orig, fun, args map argToBinding) val t = treeCopy.Apply(orig, fun, args map argToBinding)
wrapErrors(t, _.typed(t, mode, pt)) wrapErrors(t, _.typed(t, mode, pt))
} }
Expand Down
14 changes: 14 additions & 0 deletions test/files/run/dynamic-applyDynamicNamed.check
@@ -0,0 +1,14 @@
[[syntax trees at end of typer]] // newSource1.scala
[0:97]package [0:0]<empty> {
[0:97]object X extends [9:97][97]scala.AnyRef {
[9]def <init>(): [9]X.type = [9]{
[9][9][9]X.super.<init>();
[9]()
};
[17:30]private[this] val d: [21]D = [25:30][25:30][25:30]new [29:30]D();
[21]<stable> <accessor> def d: [21]D = [21][21]X.this.d;
[37:70][37:38][37:38][37]X.this.d.applyDynamicNamed(<39:43>"meth")([44:55][44][44][44]scala.this.Tuple2.apply[[44]String, [44]Int]([44:50]"value1", [53:55]10), [57:69][57][57][57]scala.this.Tuple2.apply[[57]String, [57]Int]([57:63]"value2", [66:69]100));
[77:91]<77:78><77:78>[77]X.this.d.applyDynamicNamed(<77:78>"apply")([79:90][79][79][79]scala.this.Tuple2.apply[[79]String, [79]Int]([79:85]"value1", [88:90]10))
}
}

26 changes: 26 additions & 0 deletions test/files/run/dynamic-applyDynamicNamed.scala
@@ -0,0 +1,26 @@
import scala.tools.partest.DirectTest

object Test extends DirectTest {

override def extraSettings: String =
s"-usejavacp -Xprint-pos -Xprint:typer -Yrangepos -Ystop-after:typer -d ${testOutput.path}"

override def code = """
object X {
val d = new D
d.meth(value1 = 10, value2 = 100)
d(value1 = 10)
}
""".trim

override def show(): Unit = {
Console.withErr(System.out) {
compile()
}
}
}

import language.dynamics
class D extends Dynamic {
def applyDynamicNamed(name: String)(value: (String, Any)*) = ???
}

0 comments on commit 696545d

Please sign in to comment.