Skip to content

Commit 3629b64

Browse files
kiritsukuretronym
authored andcommitted
SI-8005 Fixes NoPositon error for updateDynamic calls
Previously there occurred a NoPosition error when one asks for position information in the AST because no positions were set to the trees created during the transformation for updateDynamic calls. This commit applies range positions to the trees in order to being able to highlight them inside of the scala-ide.
1 parent 696545d commit 3629b64

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4273,7 +4273,9 @@ trait Typers extends Modes with Adaptations with Tags {
42734273
}
42744274
else if(dyna.isDynamicallyUpdatable(lhs1)) {
42754275
val rhs1 = typed(rhs, EXPRmode | BYVALmode, WildcardType)
4276-
val t = Apply(lhs1, List(rhs1))
4276+
val t = atPos(lhs1.pos.withEnd(rhs1.pos.endOrPoint)) {
4277+
Apply(lhs1, List(rhs1))
4278+
}
42774279
dyna.wrapErrors(t, _.typed1(t, mode, pt))
42784280
}
42794281
else fail()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[syntax trees at end of typer]] // newSource1.scala
2+
[0:69]package [0:0]<empty> {
3+
[0:69]object X extends [9:69][69]scala.AnyRef {
4+
[9]def <init>(): [9]X.type = [9]{
5+
[9][9][9]X.super.<init>();
6+
[9]()
7+
};
8+
[17:30]private[this] val d: [21]D = [25:30][25:30][25:30]new [29:30]D();
9+
[21]<stable> <accessor> def d: [21]D = [21][21]X.this.d;
10+
[37:49][37:38][37:38][37]X.this.d.updateDynamic(<39:44>"field")([47:49]10);
11+
[56:57][56:57][56]X.this.d.selectDynamic(<58:63>"field")
12+
}
13+
}
14+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import scala.tools.partest.DirectTest
2+
3+
object Test extends DirectTest {
4+
5+
override def extraSettings: String =
6+
s"-usejavacp -Xprint-pos -Xprint:typer -Yrangepos -Ystop-after:typer -d ${testOutput.path}"
7+
8+
override def code = """
9+
object X {
10+
val d = new D
11+
d.field = 10
12+
d.field
13+
}
14+
""".trim
15+
16+
override def show(): Unit = {
17+
Console.withErr(System.out) {
18+
compile()
19+
}
20+
}
21+
}
22+
23+
import language.dynamics
24+
class D extends Dynamic {
25+
def selectDynamic(name: String): Any = ???
26+
def updateDynamic(name: String)(value: Any): Unit = ???
27+
}
28+

0 commit comments

Comments
 (0)