Skip to content

Commit 5eae7f4

Browse files
committed
Fix #6027: Use argument span for inlined type parameters
1 parent d64efa5 commit 5eae7f4

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

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

214+
/** A map from parameter names of the inlineable method to spans of the actual arguments */
214215
private val paramSpan = new mutable.HashMap[Name, Span]
215216

216217
/** A map from references to (type and value) parameters of the inlineable method
@@ -273,6 +274,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
273274
private def computeParamBindings(tp: Type, targs: List[Tree], argss: List[List[Tree]]): Unit = tp match {
274275
case tp: PolyType =>
275276
(tp.paramNames, targs).zipped.foreach { (name, arg) =>
277+
paramSpan(name) = arg.span
276278
paramBinding(name) = arg.tpe.stripTypeVar
277279
}
278280
computeParamBindings(tp.resultType, Nil, argss)
@@ -446,7 +448,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
446448
case Some(t) if tree.isTerm && t.isSingleton =>
447449
singleton(t.dealias).withSpan(paramSpan(tree.name))
448450
case Some(t) if tree.isType =>
449-
TypeTree(t).withSpan(tree.span)
451+
TypeTree(t).withSpan(paramSpan(tree.name))
450452
case _ => tree
451453
}
452454
case tree => tree

tests/run/tasty-macro-positions.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ quoted_2.scala:[345..358]
2626
("abc": scala.Predef.String)
2727
quoted_2.scala:[369..383]
2828
_root_.scala.StringContext.apply(("abc", "": scala.<repeated>[scala#Predef.String])).s(("def": scala.<repeated>[scala.Any]))
29-
quoted_2.scala:[201..202]
29+
quoted_2.scala:[426..427]
3030
T
31-
quoted_2.scala:[201..202]
31+
quoted_2.scala:[438..444]
3232
scala.Predef.String
33-
quoted_2.scala:[201..202]
33+
quoted_2.scala:[455..460]
3434
"abc"
35-
quoted_2.scala:[201..202]
35+
quoted_2.scala:[471..472]
3636
U

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ object Test {
2727
type T
2828
type U = "abc"
2929

30-
fun3[T] // ERROR
31-
fun3[String] // ERROR
32-
fun3["abc"] // ERROR
33-
fun3[U] // ERROR
30+
fun3[T]
31+
fun3[String]
32+
fun3["abc"]
33+
fun3[U]
3434
}
35-
// 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 `'[T]` in `fun3`.
37-
// see #6027
35+
3836
}

0 commit comments

Comments
 (0)