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

Set proper position for ValDefs generated from tuples #14513

Merged
merged 1 commit into from Feb 18, 2022

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Feb 18, 2022

Previously, the span for ValDefs generated for tuples would encompas the entire expression, which led to difficulties identifying the exact path to the current position. Now, we set the span to be the same as the name underneath.

Not sure if this is a proper solution, since normally ValDefs ecompans the entire span, but in this case it makes 2 different ValDef have the same span. An alternative solution would be to find the one with point nearer to the current position.

This popped up within the Nightly tests we do in Metals.

@som-snytt
Copy link
Contributor

Relatedly, multi-assignment is also weird.

val x, y = 42

I was looking at a position ticket during pandemic fog, so I don't remember details. I closed the original ticket as working under -Yrangepos so I didn't get back to it. scala/bug#12074

compiler/src/dotty/tools/dotc/ast/Desugar.scala Outdated Show resolved Hide resolved
Comment on lines 1171 to 1172
if (mods.is(Lazy)) derivedDefDef(original, named, tpt, selector(n), mods &~ Lazy)
else derivedValDef(original, named, tpt, selector(n), mods)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of derivedValDef/derivedDefDef is that they set their span based on the original tree node, here you're going to overwrite that using withSpan, so you don't need these methods and could just inline them (derivedValDef(...) becomes valDef(ValDef(...).withMods(mods)), derivedDefDef(...) becomes DefDef(...).withMods(mods))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I inlined it all!

@tgodzik
Copy link
Contributor Author

tgodzik commented Feb 18, 2022

Relatedly, multi-assignment is also weird.

I added test case for it and it seems fine. I will also check later in Metals

Edit:
The tests here might not be checking everything exactly, I will raise another PR with a fix for that

@tgodzik tgodzik requested a review from smarter February 18, 2022 12:12
@@ -93,12 +93,6 @@ class WorksheetTest {
((m1 to m2), "val res0: String = odd"))
}

@Test def patternMatching1: Unit = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the test because it was failing and since worksheets deprecated. I think the issue is more in the test than code itself.

@@ -20,7 +20,7 @@ object Test {
// good syntax, bad semantics, detected by typer
//gowild.scala:14: error: star patterns must correspond with varargs parameters
val K(x @ _*) = k
val K(ns @ _*, x) = k // error: pattern expected
val K(ns @ _*, xx) = k // error: pattern expected
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting case. x started showing and error about being duplicate, which is true. I changed the condition to test the actual issue.

I wonder if I should add another case for the duplicate name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test, the error seems legit, though I have no idea why it popped up now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why it popped up now.

When multiple errors have the same position, we normally only display the first one.

Previously, the span for ValDefs generated for tuples would encompas the entire expression, which led to difficulties identifying the exact path to the current position. Now, we set the span to be the same as the name underneath.

Not sure if this is a proper solution, since normally ValDefs ecompans the entire span, but in this case it makes 2 different ValDef have the same span. An alternative solution would be to find the one with point nearer to the current position.

This popped up within the Nightly tests we do in Metals.
@tgodzik tgodzik merged commit 29f9d33 into scala:main Feb 18, 2022
@tgodzik tgodzik deleted the fix-ranges branch February 18, 2022 16:25
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
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 this pull request may close these issues.

None yet

5 participants