diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index c3a43f244e69..97aba9d9e106 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1665,7 +1665,7 @@ object desugar { case t => t } // This is a deliberate departure from scalac, where StringContext is not rooted (See #4732) - Apply(Select(Apply(scalaDot(nme.StringContext), strs), id), elems) + Apply(Select(Apply(scalaDot(nme.StringContext), strs), id).withSpan(tree.span), elems) case PostfixOp(t, op) => if ((ctx.mode is Mode.Type) && !isBackquoted(op) && op.name == tpnme.raw.STAR) { val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index cacfbc9d0ff9..f79900313bc6 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1245,12 +1245,12 @@ object Parsers { } }) - if (in.token == STRINGPART) - nextSegment(in.offset + (if (isTripleQuoted) 3 else 1)) + var offsetCorrection = if isTripleQuoted then 3 else 1 while (in.token == STRINGPART) - nextSegment(in.offset) + nextSegment(in.offset + offsetCorrection) + offsetCorrection = 0 if (in.token == STRINGLIT) - segmentBuf += literal(inPattern = inPattern, negOffset = in.offset, inStringInterpolation = true) + segmentBuf += literal(inPattern = inPattern, negOffset = in.offset + offsetCorrection, inStringInterpolation = true) InterpolatedString(interpolator, segmentBuf.toList) } diff --git a/compiler/test-resources/repl/i6676 b/compiler/test-resources/repl/i6676 index 9fc239ca9855..519225183e43 100644 --- a/compiler/test-resources/repl/i6676 +++ b/compiler/test-resources/repl/i6676 @@ -7,8 +7,8 @@ scala> xml" | ';' expected, but eof found scala> xml"" 1 | xml"" - | ^ - | value xml is not a member of StringContext + | ^^^^^ + | value xml is not a member of StringContext scala> xml""" 1 | xml""" | ^ diff --git a/tests/semanticdb/expect/Givens.expect.scala b/tests/semanticdb/expect/Givens.expect.scala index 432250bf3a52..95af643e9ddd 100644 --- a/tests/semanticdb/expect/Givens.expect.scala +++ b/tests/semanticdb/expect/Givens.expect.scala @@ -4,11 +4,11 @@ package b object Givens/*<-a::b::Givens.*/: extension on [A](any: A): - 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().*/" + 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().*/ extension on [B](any: B): - 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().*/" - 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().*/" + 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().*/ + 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().*/ val hello1/*<-a::b::Givens.hello1.*/ = /*->a::b::Givens.extension_sayHello_A.sayHello().*/1.sayHello val goodbye1/*<-a::b::Givens.goodbye1.*/ = /*->a::b::Givens.extension_sayGoodbye_B.sayGoodbye().*/1.sayGoodbye diff --git a/tests/semanticdb/expect/ImplicitConversion.expect.scala b/tests/semanticdb/expect/ImplicitConversion.expect.scala index 0d13a0af558c..07b7a8eea820 100644 --- a/tests/semanticdb/expect/ImplicitConversion.expect.scala +++ b/tests/semanticdb/expect/ImplicitConversion.expect.scala @@ -21,10 +21,10 @@ class ImplicitConversion/*<-example::ImplicitConversion#*/ { val x/*<-example::ImplicitConversion#x.*/: Int/*->scala::Int#*/ = /*->example::ImplicitConversion#string2Number().*/message/*->example::ImplicitConversion#message.*/ // interpolators - s"/*->scala::StringContext.apply().*/Hello $message/*->example::ImplicitConversion#message.*/ $number/*->example::ImplicitConversion#number.*//*->scala::StringContext#s().*/" + s"/*->scala::StringContext.apply().*/Hello $message/*->example::ImplicitConversion#message.*/ $number/*->example::ImplicitConversion#number.*/"/*->scala::StringContext#s().*/ /*->scala::Predef.augmentString().*/s"""/*->scala::StringContext.apply().*/Hello |$message/*->example::ImplicitConversion#message.*/ - |$number/*->example::ImplicitConversion#number.*//*->scala::StringContext#s().*/""".stripMargin/*->scala::collection::StringOps#stripMargin(+1).*/ + |$number/*->example::ImplicitConversion#number.*/"""/*->scala::StringContext#s().*/.stripMargin/*->scala::collection::StringOps#stripMargin(+1).*/ val a/*<-example::ImplicitConversion#a.*/: Int/*->scala::Int#*/ = /*->scala::Char.char2int().*/char/*->example::ImplicitConversion#char.*/ val b/*<-example::ImplicitConversion#b.*/: Long/*->scala::Long#*/ = /*->scala::Char.char2long().*/char/*->example::ImplicitConversion#char.*/ diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 1c554e0649f3..c38dec38b944 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -1315,7 +1315,7 @@ Occurrences: [6:8..6:16): sayHello <- a/b/Givens.extension_sayHello_A.sayHello(). [6:21..6:21): -> scala/StringContext.apply(). [6:34..6:37): any -> a/b/Givens.extension_sayHello_A.sayHello().(any) -[6:37..6:37): -> scala/StringContext#s(). +[6:37..6:38): " -> scala/StringContext#s(). [8:16..9:10): <- a/b/Givens.extension_sayGoodbye_B. [8:16..8:17): B <- a/b/Givens.extension_sayGoodbye_B.sayGoodbye().[B] [8:16..8:17): B <- a/b/Givens.extension_sayGoodbye_B.saySoLong().[B] @@ -1326,11 +1326,11 @@ Occurrences: [9:8..9:18): sayGoodbye <- a/b/Givens.extension_sayGoodbye_B.sayGoodbye(). [9:23..9:23): -> scala/StringContext.apply(). [9:38..9:41): any -> a/b/Givens.extension_sayGoodbye_B.sayGoodbye().(any) -[9:41..9:41): -> scala/StringContext#s(). +[9:41..9:42): " -> scala/StringContext#s(). [10:8..10:17): saySoLong <- a/b/Givens.extension_sayGoodbye_B.saySoLong(). [10:22..10:22): -> scala/StringContext.apply(). [10:37..10:40): any -> a/b/Givens.extension_sayGoodbye_B.saySoLong().(any) -[10:40..10:40): -> scala/StringContext#s(). +[10:40..10:41): " -> scala/StringContext#s(). [12:6..12:12): hello1 <- a/b/Givens.hello1. [12:15..12:15): -> a/b/Givens.extension_sayHello_A.sayHello(). [13:6..13:14): goodbye1 <- a/b/Givens.goodbye1. @@ -1445,12 +1445,12 @@ Occurrences: [23:4..23:4): -> scala/StringContext.apply(). [23:11..23:18): message -> example/ImplicitConversion#message. [23:20..23:26): number -> example/ImplicitConversion#number. -[23:26..23:26): -> scala/StringContext#s(). +[23:26..23:27): " -> scala/StringContext#s(). [24:2..24:2): -> scala/Predef.augmentString(). [24:6..24:6): -> scala/StringContext.apply(). [25:7..25:14): message -> example/ImplicitConversion#message. [26:7..26:13): number -> example/ImplicitConversion#number. -[26:13..26:13): -> scala/StringContext#s(). +[26:15..26:16): " -> scala/StringContext#s(). [26:17..26:28): stripMargin -> scala/collection/StringOps#stripMargin(+1). [28:6..28:7): a <- example/ImplicitConversion#a. [28:9..28:12): Int -> scala/Int#