Skip to content

Commit 073ebbd

Browse files
committed
Merge pull request scala#3197 from retronym/merge/2.10.x-positions-to-master
Merge 2.10.x, and PR scala#3196, to master
2 parents a6f7582 + f30ae61 commit 073ebbd

10 files changed

+178
-8
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3917,9 +3917,14 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
39173917

39183918
def typedNamedApply(orig: Tree, fun: Tree, args: List[Tree], mode: Mode, pt: Type): Tree = {
39193919
def argToBinding(arg: Tree): Tree = arg match {
3920-
case AssignOrNamedArg(Ident(name), rhs) => gen.mkTuple(List(CODE.LIT(name.toString), rhs))
3921-
case _ => gen.mkTuple(List(CODE.LIT(""), arg))
3920+
case AssignOrNamedArg(i @ Ident(name), rhs) =>
3921+
atPos(i.pos.withEnd(rhs.pos.end)) {
3922+
gen.mkTuple(List(atPos(i.pos)(CODE.LIT(name.toString)), rhs))
3923+
}
3924+
case _ =>
3925+
gen.mkTuple(List(CODE.LIT(""), arg))
39223926
}
3927+
39233928
val t = treeCopy.Apply(orig, fun, args map argToBinding)
39243929
wrapErrors(t, _.typed(t, mode, pt))
39253930
}
@@ -3979,7 +3984,10 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
39793984
case Some((opName, treeInfo.Applied(_, targs, _))) =>
39803985
val fun = gen.mkTypeApply(Select(qual, opName), targs)
39813986
if (opName == nme.updateDynamic) suppressMacroExpansion(fun) // SI-7617
3982-
atPos(qual.pos)(Apply(fun, Literal(Constant(name.decode)) :: Nil))
3987+
val nameStringLit = atPos(treeSelection.pos.withStart(treeSelection.pos.point).makeTransparent) {
3988+
Literal(Constant(name.decode))
3989+
}
3990+
atPos(qual.pos)(Apply(fun, List(nameStringLit)))
39833991
case _ =>
39843992
setError(tree)
39853993
}
@@ -4175,7 +4183,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
41754183
}
41764184
else if(dyna.isDynamicallyUpdatable(lhs1)) {
41774185
val rhs1 = typedByValueExpr(rhs)
4178-
val t = Apply(lhs1, List(rhs1))
4186+
val t = atPos(lhs1.pos.withEnd(rhs1.pos.end)) {
4187+
Apply(lhs1, List(rhs1))
4188+
}
41794189
dyna.wrapErrors(t, _.typed1(t, mode, pt))
41804190
}
41814191
else fail()

test/files/neg/applydynamic_sip.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ applydynamic_sip.scala:18: error: type mismatch;
2222
error after rewriting to Test.this.bad1.selectDynamic("sel")
2323
possible cause: maybe a wrong Dynamic method signature?
2424
bad1.sel
25-
^
25+
^
2626
applydynamic_sip.scala:19: error: type mismatch;
2727
found : String("sel")
2828
required: Int
2929
error after rewriting to Test.this.bad1.applyDynamic("sel")
3030
possible cause: maybe a wrong Dynamic method signature?
3131
bad1.sel(1)
32-
^
32+
^
3333
applydynamic_sip.scala:20: error: type mismatch;
3434
found : String("sel")
3535
required: Int
3636
error after rewriting to Test.this.bad1.applyDynamicNamed("sel")
3737
possible cause: maybe a wrong Dynamic method signature?
3838
bad1.sel(a = 1)
39-
^
39+
^
4040
applydynamic_sip.scala:20: error: reassignment to val
4141
bad1.sel(a = 1)
4242
^
@@ -46,7 +46,7 @@ applydynamic_sip.scala:21: error: type mismatch;
4646
error after rewriting to Test.this.bad1.updateDynamic("sel")
4747
possible cause: maybe a wrong Dynamic method signature?
4848
bad1.sel = 1
49-
^
49+
^
5050
applydynamic_sip.scala:29: error: Int does not take parameters
5151
error after rewriting to Test.this.bad2.selectDynamic("sel")
5252
possible cause: maybe a wrong Dynamic method signature?
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:67]package [0:0]<empty> {
3+
[0:67]object X extends [9:67][67]scala.AnyRef {
4+
[67]def <init>(): [9]X.type = [67]{
5+
[67][67][67]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.applyDynamic(<39:45>"method")([46:48]10);
11+
[56:61]<56:57><56:57>[56]X.this.d.applyDynamic(<56:57>"apply")([58:60]10)
12+
}
13+
}
14+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.method(10)
12+
d(10)
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 applyDynamic(name: String)(value: Any) = ???
26+
}
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:97]package [0:0]<empty> {
3+
[0:97]object X extends [9:97][97]scala.AnyRef {
4+
[97]def <init>(): [9]X.type = [97]{
5+
[97][97][97]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:70][37:38][37:38][37]X.this.d.applyDynamicNamed(<39:43>"meth")([44:55][44][44]scala.Tuple2.apply[[44]String, [44]Int]([44:50]"value1", [53:55]10), [57:69][57][57]scala.Tuple2.apply[[57]String, [57]Int]([57:63]"value2", [66:69]100));
11+
[77:91]<77:78><77:78>[77]X.this.d.applyDynamicNamed(<77:78>"apply")([79:90][79][79]scala.Tuple2.apply[[79]String, [79]Int]([79:85]"value1", [88:90]10))
12+
}
13+
}
14+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.meth(value1 = 10, value2 = 100)
12+
d(value1 = 10)
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 applyDynamicNamed(name: String)(value: (String, Any)*) = ???
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[syntax trees at end of typer]] // newSource1.scala
2+
[0:50]package [0:0]<empty> {
3+
[0:50]object X extends [9:50][50]scala.AnyRef {
4+
[50]def <init>(): [9]X.type = [50]{
5+
[50][50][50]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:38][37:38][37]X.this.d.selectDynamic(<39:44>"field")
11+
}
12+
}
13+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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
12+
}
13+
""".trim
14+
15+
override def show(): Unit = {
16+
Console.withErr(System.out) {
17+
compile()
18+
}
19+
}
20+
}
21+
22+
import language.dynamics
23+
class D extends Dynamic {
24+
def selectDynamic(name: String) = ???
25+
}
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+
[69]def <init>(): [9]X.type = [69]{
5+
[69][69][69]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)