-
Notifications
You must be signed in to change notification settings - Fork 395
Description
Describe the bug
documenting the discussion in #3885 (comment)
I see that in case param is named it is reused as an enumeration binding.
Given:
object A {
val res3 = List(1, 2, 3)
.map(x => x + 1)
.map(x => x + 2)
}Result (duplicated x):
object A {
val res3 = {
for {
x <- List(1, 2, 3)
x = x + 1
} yield {
x + 2
}
}
}A complication for solving the bug is that,
someone might put longer code inside each enumeration there, and as a result, some inner context x might not refer to the outer context x for example.
List(1, 2, 3)
.map{ x =>
for(x <- 1 to 5)
println(x)
x + 3
} .filter (x => x > 5)
Now in this example, the x inside println(x) is not the same x as in .map{ x => and it is a challenge to know when to replace and when not.
For now,
the benefit of generating something like:
x <- List(1, 2, 3)
x = x + 1
in such cases is that it shows an error, which prompts the programmer to go through the code and manually fix it.
Expected behavior
Metals should correctly find and rename the overlapping param names for generating a for comprehension.
Operating system
No response
Editor/Extension
No response
Version of Metals
v0.11.7-SNAPSHOT
Extra context or search terms
No response