Skip to content

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

Merged
merged 6 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/test-resources/repl/i6676
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
| ^
Expand Down
6 changes: 3 additions & 3 deletions tests/semanticdb/expect/Givens.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/semanticdb/expect/ImplicitConversion.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
Expand Down
10 changes: 5 additions & 5 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
Expand Down Expand Up @@ -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#
Expand Down