Skip to content

Commit d64efa5

Browse files
committed
Fix scala#6026: Use argument position for singleton arguments
1 parent 51d8cab commit d64efa5

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
211211
*/
212212
private val paramBinding = new mutable.HashMap[Name, Type]
213213

214+
private val paramSpan = new mutable.HashMap[Name, Span]
215+
214216
/** A map from references to (type and value) parameters of the inlineable method
215217
* to their corresponding argument or proxy references, as given by `paramBinding`.
216218
*/
@@ -277,6 +279,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
277279
case tp: MethodType =>
278280
assert(argss.nonEmpty, i"missing bindings: $tp in $call")
279281
(tp.paramNames, tp.paramInfos, argss.head).zipped.foreach { (name, paramtp, arg) =>
282+
paramSpan(name) = arg.span
280283
paramBinding(name) = arg.tpe.dealias match {
281284
case _: SingletonType if isIdempotentExpr(arg) => arg.tpe
282285
case _ => paramBindingDef(name, paramtp, arg, bindingsBuf).symbol.termRef
@@ -441,8 +444,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
441444
case tree: Ident =>
442445
paramProxy.get(tree.tpe) match {
443446
case Some(t) if tree.isTerm && t.isSingleton =>
444-
// FIXME wrong span, this is the span inside the inline method
445-
singleton(t.dealias).withSpan(tree.span)
447+
singleton(t.dealias).withSpan(paramSpan(tree.name))
446448
case Some(t) if tree.isType =>
447449
TypeTree(t).withSpan(tree.span)
448450
case _ => tree

tests/run/tasty-macro-positions.check

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
quoted_2.scala:[103..103]
1+
quoted_2.scala:[173..174]
22
a
3-
quoted_2.scala:[103..103]
3+
quoted_2.scala:[184..185]
44
b
5-
quoted_2.scala:[213..214]
5+
quoted_2.scala:[195..196]
66
c
7-
quoted_2.scala:[224..225]
7+
quoted_2.scala:[206..207]
88
d
9-
quoted_2.scala:[103..103]
9+
quoted_2.scala:[217..222]
1010
"abc"
11-
quoted_2.scala:[259..272]
11+
quoted_2.scala:[232..245]
1212
("abc": scala.Predef.String)
13-
quoted_2.scala:[282..296]
13+
quoted_2.scala:[255..269]
1414
_root_.scala.StringContext.apply(("abc", "": scala.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[scala.Any]))
15-
quoted_2.scala:[154..154]
15+
quoted_2.scala:[281..282]
1616
a
17-
quoted_2.scala:[154..154]
17+
quoted_2.scala:[293..294]
1818
b
19-
quoted_2.scala:[350..351]
19+
quoted_2.scala:[305..306]
2020
c
21-
quoted_2.scala:[362..363]
21+
quoted_2.scala:[317..318]
2222
d
23-
quoted_2.scala:[154..154]
23+
quoted_2.scala:[329..334]
2424
"abc"
25-
quoted_2.scala:[399..412]
25+
quoted_2.scala:[345..358]
2626
("abc": scala.Predef.String)
27-
quoted_2.scala:[423..437]
27+
quoted_2.scala:[369..383]
2828
_root_.scala.StringContext.apply(("abc", "": scala.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[scala.Any]))
2929
quoted_2.scala:[201..202]
3030
T

tests/run/tasty-macro-positions/quoted_2.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ object Test {
88
def c: String = "abc"
99
def d: 42 = 42
1010

11-
fun(a) // ERROR
12-
fun(b) // ERROR
11+
fun(a)
12+
fun(b)
1313
fun(c)
1414
fun(d)
15-
fun("abc") // ERROR
15+
fun("abc")
1616
fun("abc": String)
1717
fun(s"abc${"def"}")
1818

19-
fun2(a) // ERROR
20-
fun2(b) // ERROR
19+
fun2(a)
20+
fun2(b)
2121
fun2(c)
2222
fun2(d)
23-
fun2("abc") // ERROR
23+
fun2("abc")
2424
fun2("abc": String)
2525
fun2(s"abc${"def"}")
2626

@@ -33,6 +33,6 @@ object Test {
3333
fun3[U] // ERROR
3434
}
3535
// FIXME all the lines marked as ERROR have the wrong position on the three of the argument.
36-
// they all have as source file this file but the span of `'x` in `fun` or `fun2`.
37-
// see #6026 and #6027
36+
// they all have as source file this file but the span of `'[T]` in `fun3`.
37+
// see #6027
3838
}

0 commit comments

Comments
 (0)