Skip to content

Desugared guard (withFilter) in for comp fails position check #13037

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

Closed
som-snytt opened this issue Sep 25, 2024 · 1 comment · Fixed by scala/scala#10870
Closed

Desugared guard (withFilter) in for comp fails position check #13037

som-snytt opened this issue Sep 25, 2024 · 1 comment · Fixed by scala/scala#10870
Assignees
Milestone

Comments

@som-snytt
Copy link

som-snytt commented Sep 25, 2024

Reproduction steps

Scala version: 2.13.15

//> using options -Yvalidate-pos:typer
object A {
  def f(list: List[String]) = for (string <- list if string.length > 5)
    println(string)
}

Problem

def f(list: List[String]) = list.withFilter(((string) => string.length.$greater(5))).foreach(((string) => println(string)))

The problem is with the position of the string parameter.

For patvar usage tracking scala/scala#10812, the pattern tree and its duplicate in the construction of a guard expression were reversed at https://github.com/scala/scala/blob/v2.13.15/src/reflect/scala/reflect/internal/TreeGen.scala#L728 because one patvar is now tracked as an "alias" of the original other. The result is that the tree positions, which are subtly different, are reversed. In particular, one pos is an offset and the other is a range.

In 2.13.14, the offset range of the parameter to the withFilter function ([111]) is also out of range of the enclosing trees ([121:146]), but by some quirk, it doesn't fail validation. (The quirky feature is that "range" means "non-synthetic", so the enclosed tree must have a range to be checkable.)

Noticed at scoverage/scalac-scoverage-plugin#641

@som-snytt
Copy link
Author

Although -Yvalidate-pos is a "private" option, labelling as a "blocker" because it will block me from getting a good night's rest.

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

Successfully merging a pull request may close this issue.

2 participants