Skip to content
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

Incorrect position in desugaring of a destructor val statement #13078

Open
kasiaMarek opened this issue Jan 9, 2025 · 2 comments · May be fixed by scala/scala#11032
Open

Incorrect position in desugaring of a destructor val statement #13078

kasiaMarek opened this issue Jan 9, 2025 · 2 comments · May be fixed by scala/scala#11032
Assignees

Comments

@kasiaMarek
Copy link
Member

Reproduction steps

Scala version: 2.13.15

object O {
    def runtimeResources = {
        val (singleFiles, correctEntries) = (???, ???)
    }
}

desugars to (outprint with -Vprint -Vprint-pos)

[24:126]package [24:24]<empty> {
  [24:126]object O extends [33:126][33]scala.AnyRef {
    [33]def <init>(): [33]O.type = [33]{
      [33][33][33]O.super.<init>();
      [33]()
    };
    [39:124]def runtimeResources: [43]Unit = [62:124]{
      <72:118><synthetic> <artifact> private[this] val x$1: [76](Nothing, Nothing) = <76:118>[108:118]([108:118][108][108]scala.Tuple2.apply[[108]Nothing, [108]Nothing]([109:112]scala.Predef.???, [114:117]scala.Predef.???): [108]<type: [NoPosition][108:118][108][108]scala.Tuple2.apply[[108]Nothing, [108]Nothing]([109:112]scala.Predef.???, [114:117]scala.Predef.???): @[108]scala.unchecked>) match {
        <76:105>case <76:105>[76]<type: [76]scala.Tuple2>(<77:88>(singleFiles @ [77]_), <90:104>(correctEntries @ [90]_)) =>
        // I would expect the positions in line below to be (<77:88>singleFiles, <90:104>correctEntries) or for `x$1` definition to have zero-extend position
        <76:105><76:105><76:105>scala.Tuple2.apply[[76]Nothing, [76]Nothing](<76:105>singleFiles, <76:105>correctEntries)
      };
      [77:88]val singleFiles: [77]Nothing = [77]x$1._1;
      [90:104]val correctEntries: [90]Nothing = [90]x$1._2;
      [123]()
    }
  }
}

Problem

As noted in the comment I'd expect the positions in the apply with (singleFiles, correctEntries) to either point to the same positions as definitions of singleFiles and correctEntries or for the whole x$1 synthetic definition to have zero extend position.

Extra context

scalameta/metals#7086

@som-snytt
Copy link

Assigning myself because I intended to look at the related issue with multiple initialization.

Similar positions were important for for-comprehension desugaring and patvar tracking.

(Currently, I'm learning about dotty positions under inlining.)

@som-snytt
Copy link

I commented on the metals ticket. Here is what I see now:

[[syntax trees at end of                     typer]] // t13078.scala
[1:95]package [1:1]<empty> {
  [1:95]object O extends [10:95][10]scala.AnyRef {
    [10]def <init>(): [10]O.type = [10]{
      [10][10][10]O.super.<init>();
      [10]()
    };
    [14:93]def runtimeResources: [18]Unit = [37:93]{
      <47:89><synthetic> <artifact> private[this] val x$1: [47](Nothing, Nothing) = <47:89>[79:89]([79:89][79][79]scala.Tuple2.apply[[79]Nothing, [79]Nothing]([80:83]scala.Predef.???, [85:88]scala.Predef.???): [79]<type: [NoPosition][79:89][79][79]scala.Tuple2.apply[[79]Nothing, [79]Nothing]([80:83]scala.Predef.???, [85:88]scala.Predef.???): @[79]scala.unchecked>) match {
        <47:76>case <47:76>[47]<type: [47]scala.Tuple2>(<48:59>(singleFiles @ [48]_), <61:75>(correctEntries @ [61]_)) => <47:76><47:76><47:76>scala.Tuple2.apply[[47]Nothing, [47]Nothing](<48:59>singleFiles, <61:75>correctEntries)
      };
      <43:89>val singleFiles: [48]Nothing = [48]x$1._1;
      <43:89>val correctEntries: [61]Nothing = [61]x$1._2;
      [92]()
    }
  }
}

I see that the two val members now have transparent positions after the "multivar" position fix. When multiple members are introduced together, either as val x, y = z or val P(x, y) = z, they get a transparent pos for the whole range, with a name pos at the name, and an offset point also at the name. (To clarify, the name pos shows up as the symbol position. It is a bit different from Dotty.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants