Skip to content

Commit 25c0305

Browse files
Merge pull request #8629 from martijnhoekstra/interpolatedPos
Correct offset for single-string interpolation
2 parents a0e5a8e + 31e9464 commit 25c0305

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ object desugar {
16651665
case t => t
16661666
}
16671667
// This is a deliberate departure from scalac, where StringContext is not rooted (See #4732)
1668-
Apply(Select(Apply(scalaDot(nme.StringContext), strs), id), elems)
1668+
Apply(Select(Apply(scalaDot(nme.StringContext), strs), id).withSpan(tree.span), elems)
16691669
case PostfixOp(t, op) =>
16701670
if ((ctx.mode is Mode.Type) && !isBackquoted(op) && op.name == tpnme.raw.STAR) {
16711671
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,12 @@ object Parsers {
12451245
}
12461246
})
12471247

1248-
if (in.token == STRINGPART)
1249-
nextSegment(in.offset + (if (isTripleQuoted) 3 else 1))
1248+
var offsetCorrection = if isTripleQuoted then 3 else 1
12501249
while (in.token == STRINGPART)
1251-
nextSegment(in.offset)
1250+
nextSegment(in.offset + offsetCorrection)
1251+
offsetCorrection = 0
12521252
if (in.token == STRINGLIT)
1253-
segmentBuf += literal(inPattern = inPattern, negOffset = in.offset, inStringInterpolation = true)
1253+
segmentBuf += literal(inPattern = inPattern, negOffset = in.offset + offsetCorrection, inStringInterpolation = true)
12541254

12551255
InterpolatedString(interpolator, segmentBuf.toList)
12561256
}

compiler/test-resources/repl/i6676

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ scala> xml"
77
| ';' expected, but eof found
88
scala> xml""
99
1 | xml""
10-
| ^
11-
| value xml is not a member of StringContext
10+
| ^^^^^
11+
| value xml is not a member of StringContext
1212
scala> xml"""
1313
1 | xml"""
1414
| ^

tests/semanticdb/expect/Givens.expect.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ package b
44
object Givens/*<-a::b::Givens.*/:
55

66
extension on [A](any: A):
7-
def /*<-a::b::Givens.extension_sayHello_A.*//*<-a::b::Givens.extension_sayHello_A.sayHello().[A]*//*<-a::b::Givens.extension_sayHello_A.sayHello().(any)*//*->a::b::Givens.extension_sayHello_A.sayHello().[A]*/sayHello/*<-a::b::Givens.extension_sayHello_A.sayHello().*/ = s"/*->scala::StringContext.apply().*/Hello, I am $any/*->a::b::Givens.extension_sayHello_A.sayHello().(any)*//*->scala::StringContext#s().*/"
7+
def /*<-a::b::Givens.extension_sayHello_A.*//*<-a::b::Givens.extension_sayHello_A.sayHello().[A]*//*<-a::b::Givens.extension_sayHello_A.sayHello().(any)*//*->a::b::Givens.extension_sayHello_A.sayHello().[A]*/sayHello/*<-a::b::Givens.extension_sayHello_A.sayHello().*/ = s"/*->scala::StringContext.apply().*/Hello, I am $any/*->a::b::Givens.extension_sayHello_A.sayHello().(any)*/"/*->scala::StringContext#s().*/
88

99
extension on [B](any: B):
10-
def sa/*<-a::b::Givens.extension_sayGoodbye_B.*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*//*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*->a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*/yGoodbye/*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().*/ = s"/*->scala::StringContext.apply().*/Goodbye, from $any/*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*//*->scala::StringContext#s().*/"
11-
def saySoLong/*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().*/ = s"/*->scala::StringContext.apply().*/So Long, from $any/*->a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*//*->scala::StringContext#s().*/"
10+
def sa/*<-a::b::Givens.extension_sayGoodbye_B.*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*//*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*//*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*//*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().[B]*//*->a::b::Givens.extension_sayGoodbye_B.saySoLong().[B]*/yGoodbye/*<-a::b::Givens.extension_sayGoodbye_B.sayGoodbye().*/ = s"/*->scala::StringContext.apply().*/Goodbye, from $any/*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().(any)*/"/*->scala::StringContext#s().*/
11+
def saySoLong/*<-a::b::Givens.extension_sayGoodbye_B.saySoLong().*/ = s"/*->scala::StringContext.apply().*/So Long, from $any/*->a::b::Givens.extension_sayGoodbye_B.saySoLong().(any)*/"/*->scala::StringContext#s().*/
1212

1313
val hello1/*<-a::b::Givens.hello1.*/ = /*->a::b::Givens.extension_sayHello_A.sayHello().*/1.sayHello
1414
val goodbye1/*<-a::b::Givens.goodbye1.*/ = /*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().*/1.sayGoodbye

tests/semanticdb/expect/ImplicitConversion.expect.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ImplicitConversion/*<-example::ImplicitConversion#*/ {
2121
val x/*<-example::ImplicitConversion#x.*/: Int/*->scala::Int#*/ = /*->example::ImplicitConversion#string2Number().*/message/*->example::ImplicitConversion#message.*/
2222

2323
// interpolators
24-
s"/*->scala::StringContext.apply().*/Hello $message/*->example::ImplicitConversion#message.*/ $number/*->example::ImplicitConversion#number.*//*->scala::StringContext#s().*/"
24+
s"/*->scala::StringContext.apply().*/Hello $message/*->example::ImplicitConversion#message.*/ $number/*->example::ImplicitConversion#number.*/"/*->scala::StringContext#s().*/
2525
/*->scala::Predef.augmentString().*/s"""/*->scala::StringContext.apply().*/Hello
2626
|$message/*->example::ImplicitConversion#message.*/
27-
|$number/*->example::ImplicitConversion#number.*//*->scala::StringContext#s().*/""".stripMargin/*->scala::collection::StringOps#stripMargin(+1).*/
27+
|$number/*->example::ImplicitConversion#number.*/"""/*->scala::StringContext#s().*/.stripMargin/*->scala::collection::StringOps#stripMargin(+1).*/
2828

2929
val a/*<-example::ImplicitConversion#a.*/: Int/*->scala::Int#*/ = /*->scala::Char.char2int().*/char/*->example::ImplicitConversion#char.*/
3030
val b/*<-example::ImplicitConversion#b.*/: Long/*->scala::Long#*/ = /*->scala::Char.char2long().*/char/*->example::ImplicitConversion#char.*/

tests/semanticdb/metac.expect

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ Occurrences:
13151315
[6:8..6:16): sayHello <- a/b/Givens.extension_sayHello_A.sayHello().
13161316
[6:21..6:21): -> scala/StringContext.apply().
13171317
[6:34..6:37): any -> a/b/Givens.extension_sayHello_A.sayHello().(any)
1318-
[6:37..6:37): -> scala/StringContext#s().
1318+
[6:37..6:38): " -> scala/StringContext#s().
13191319
[8:16..9:10): <- a/b/Givens.extension_sayGoodbye_B.
13201320
[8:16..8:17): B <- a/b/Givens.extension_sayGoodbye_B.sayGoodbye().[B]
13211321
[8:16..8:17): B <- a/b/Givens.extension_sayGoodbye_B.saySoLong().[B]
@@ -1326,11 +1326,11 @@ Occurrences:
13261326
[9:8..9:18): sayGoodbye <- a/b/Givens.extension_sayGoodbye_B.sayGoodbye().
13271327
[9:23..9:23): -> scala/StringContext.apply().
13281328
[9:38..9:41): any -> a/b/Givens.extension_sayGoodbye_B.sayGoodbye().(any)
1329-
[9:41..9:41): -> scala/StringContext#s().
1329+
[9:41..9:42): " -> scala/StringContext#s().
13301330
[10:8..10:17): saySoLong <- a/b/Givens.extension_sayGoodbye_B.saySoLong().
13311331
[10:22..10:22): -> scala/StringContext.apply().
13321332
[10:37..10:40): any -> a/b/Givens.extension_sayGoodbye_B.saySoLong().(any)
1333-
[10:40..10:40): -> scala/StringContext#s().
1333+
[10:40..10:41): " -> scala/StringContext#s().
13341334
[12:6..12:12): hello1 <- a/b/Givens.hello1.
13351335
[12:15..12:15): -> a/b/Givens.extension_sayHello_A.sayHello().
13361336
[13:6..13:14): goodbye1 <- a/b/Givens.goodbye1.
@@ -1445,12 +1445,12 @@ Occurrences:
14451445
[23:4..23:4): -> scala/StringContext.apply().
14461446
[23:11..23:18): message -> example/ImplicitConversion#message.
14471447
[23:20..23:26): number -> example/ImplicitConversion#number.
1448-
[23:26..23:26): -> scala/StringContext#s().
1448+
[23:26..23:27): " -> scala/StringContext#s().
14491449
[24:2..24:2): -> scala/Predef.augmentString().
14501450
[24:6..24:6): -> scala/StringContext.apply().
14511451
[25:7..25:14): message -> example/ImplicitConversion#message.
14521452
[26:7..26:13): number -> example/ImplicitConversion#number.
1453-
[26:13..26:13): -> scala/StringContext#s().
1453+
[26:15..26:16): " -> scala/StringContext#s().
14541454
[26:17..26:28): stripMargin -> scala/collection/StringOps#stripMargin(+1).
14551455
[28:6..28:7): a <- example/ImplicitConversion#a.
14561456
[28:9..28:12): Int -> scala/Int#

0 commit comments

Comments
 (0)