Skip to content

Improve checking LHS of Assign #22977

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

Merged
merged 1 commit into from
May 7, 2025
Merged

Conversation

som-snytt
Copy link
Contributor

Fixes #22970

Simple example showing how awkward this is compared to a traversal, where there is more control when descending.

Previously, it "ignored" the LHS of Assign to avoid taking x = y as ref to x instead of assignment to.

Now, "mark" the LHS as assignment, so transformIdent and Select set a "mode" flag, such that x is correctly taken as either a ref or assign to x.

Probably there is more complex syntax to handle as LHS, but I haven't had coffee yet.

@som-snytt som-snytt force-pushed the issue/22970-var-import branch from d38c344 to 48e3493 Compare April 11, 2025 14:27
@som-snytt som-snytt force-pushed the issue/22970-var-import branch from 48e3493 to 05cd547 Compare April 30, 2025 05:14
@som-snytt som-snytt marked this pull request as ready for review April 30, 2025 05:14
@Gedochao Gedochao requested a review from tgodzik May 6, 2025 09:56
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM

@tgodzik
Copy link
Contributor

tgodzik commented May 6, 2025

Could rebase on main? There seems to be some conflicts.

@som-snytt som-snytt force-pushed the issue/22970-var-import branch from 05cd547 to e7d18a7 Compare May 6, 2025 17:25
@som-snytt
Copy link
Contributor Author

som-snytt commented May 6, 2025

Probably there is more complex syntax to handle as LHS, but I haven't had coffee yet.

I think it's time for that coffee.

Edit: by which I mean, I still have reservations about this simple solution, but I will follow up with an over-engineered solution at a future date.

@tgodzik tgodzik merged commit 9bee756 into scala:main May 7, 2025
29 checks passed
@som-snytt som-snytt deleted the issue/22970-var-import branch May 7, 2025 15:29
tgodzik pushed a commit to scala/scala3-lts that referenced this pull request May 12, 2025
Fixes scala#22970

Simple example showing how awkward this is compared to a traversal,
where there is more control when descending.

Previously, it "ignored" the LHS of Assign to avoid taking `x = y` as
ref to `x` instead of assignment to.

Now, "mark" the LHS as assignment, so `transformIdent` and `Select` set
a "mode" flag, such that `x` is correctly taken as either a ref or
assign to `x`.

Probably there is more complex syntax to handle as LHS, but I haven't
had coffee yet.
[Cherry-picked 9bee756]
odersky pushed a commit to dotty-staging/dotty that referenced this pull request May 12, 2025
Fixes scala#22970

Simple example showing how awkward this is compared to a traversal,
where there is more control when descending.

Previously, it "ignored" the LHS of Assign to avoid taking `x = y` as
ref to `x` instead of assignment to.

Now, "mark" the LHS as assignment, so `transformIdent` and `Select` set
a "mode" flag, such that `x` is correctly taken as either a ref or
assign to `x`.

Probably there is more complex syntax to handle as LHS, but I haven't
had coffee yet.
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.

False positive warning: unused import when var symbol is used only as assignment target
2 participants