Skip to content

Complications recovering positions in String interpolators #6432

@nicolasstucki

Description

@nicolasstucki

Foo.scala

class Foo {
  s"abc${"123"}xyz${1}fgh"
}
dotc Foo.scala -Xprint:front -Yprint-pos -Ydebug-pos
package <empty>@Foo.scala<0..0> {
  class Foo() extends Object@Foo.scala<6..6>@Foo.scala<6..6>()@Foo.scala<6..6> {
     
    _root_@Foo.scala<15..15>.scala@Foo.scala<15..15>.StringContext@
      Foo.scala<15..15>
    .apply@Foo.scala<15..15>(
      ["abc"@Foo.scala<15..20>,"xyz"@Foo.scala<27..31>,"fgh"@Foo.scala<34..38>
         : 
      String]@Foo.scala<15..38> :String*@Foo.scala<15..38>
    )@Foo.scala<15..38>.s@Foo.scala<15..38>(
      ["123"@Foo.scala<21..26>,1@Foo.scala<32..33> : Any]@Foo.scala<21..33> :
        Any*
      @Foo.scala<21..33>
    )@Foo.scala<14..38>
  }@Foo.scala[0..6..40]
}@Foo.scala<0..40>

The inconsistent part is

["abc"@Foo.scala<15..20>,"xyz"@Foo.scala<27..31>,"fgh"@Foo.scala<34..38>: String]

which corresponds to

s"abc${"123"}xyz${1}fgh"
 ^^^^^       ^^^^   ^^^^

but if an error should be emtted on some of those literals they should be on

s"abc${"123"}xyz${1}fgh"
  ^^^        ^^^    ^^^

Furthermore, if a macro checks the contents of the string and wants to emits an error in a partial part of the string they must figure out where the strings actually start and end. This gets even more complicated if we consider are a multiline string.

I would suggest changing the positions of each literal to match

s"abc${"123"}xyz${1}fgh"
  ^^^        ^^^    ^^^

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions