-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Correct offset for single-string interpolation #8629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c691beb
a8040df
e55aa85
506a9c4
c3432ff
31e9464
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ scala> xml" | |
| ';' expected, but eof found | ||
scala> xml"" | ||
1 | xml"" | ||
| ^ | ||
| value xml is not a member of StringContext | ||
| ^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now aligned with the implementation, but it still looks wrong to me. Analogous to
I would have expected
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, that would be the correct position. Change Desugar.scala#L1668 to Apply(Select(Apply(scalaDot(nme.StringContext).withSpan(tree.span), strs), id), elems) |
||
| value xml is not a member of StringContext | ||
scala> xml""" | ||
1 | xml""" | ||
| ^ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dotty.tools | ||
package dotc | ||
package parsing | ||
|
||
import ast.untpd._ | ||
import org.junit.Test | ||
|
||
class PositionTest extends ParserTest { | ||
martijnhoekstra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
val tq = "\"\"\"" | ||
val program = s""" | ||
|class A { | ||
| val expr = 42 | ||
| val s0 = s"string1" | ||
| val s1 = s"string1$${expr}string2" | ||
| val s2 = s"string1$${expr}string2$${expr}string3" | ||
| val s0m = s${tq}string1${tq} | ||
| val s1m = s${tq}string1$${expr}string2${tq} | ||
| val s2m = s${tq}string1$${expr}string2$${expr}string3${tq} | ||
|}""".stripMargin | ||
|
||
@Test | ||
def interpolationLiteralPosition: Unit = { | ||
val t = parseText(program) | ||
t match { | ||
case PackageDef(_, List(TypeDef(_, Template(_, _, _, statements: List[Tree])))) => { | ||
val interpolations = statements.collect{ case ValDef(_, _, InterpolatedString(_, int)) => int } | ||
val lits = interpolations.flatten.flatMap { | ||
case l @ Literal(_) => List(l) | ||
case Thicket(trees) => trees.collect { case l @ Literal(_) => l } | ||
} | ||
for { | ||
lit <- lits | ||
Literal(c) = lit | ||
str <- List(c.value).collect { case str: String => str} | ||
} { | ||
val fromPos = program.substring(lit.span.start, lit.span.end) | ||
assert(fromPos == str, s"$fromPos == $str") | ||
} | ||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.