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

Detect assignments in calls to avoid false positive lints #639

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Nov 25, 2024

Addresses posit-dev/positron#3048.

Positron Notes

Release Notes

New Features

  • N/A

Bug Fixes

  • Assignments in function calls (e.g. list(x <- 1)) are now detected by the missing symbol linter to avoid annoying false positive diagnostics (Diagnostics: No symbol in scope when assigning variables in function calls positron#3048). The downside is that this causes false negatives when the assignment happens in a call with local scope, e.g. in local() or test_that(). In these cases the nested assignments will incorrectly overlast the end of the call. We prefer to be overly permissive than overly cautious in these matters.

QA Notes

Assignments in calls, e.g. list(x <- 1) should now be treated the same as at top-level. Any further references to x at top level should not be linted, e.g. y should cause a lint but not x in:

list(x <- 1)
x; y

Note that calls can be nested list(x <- 1, list(y, x, y <- 2), 1, y).

In that example, the first y should in principle be linted as it hasn't been defined yet but we don't support this sort of lints inside arguments yet.

context.in_call = true;
let context = &mut context;
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 the crux of the fix. We don't create a new context so that assignments may apply to the caller's context.

@lionel- lionel- requested a review from DavisVaughan November 25, 2024 14:09
crates/ark/src/lsp/diagnostics.rs Show resolved Hide resolved
crates/ark/src/lsp/diagnostics.rs Show resolved Hide resolved
crates/ark/src/lsp/diagnostics.rs Show resolved Hide resolved
Comment on lines +789 to +790
// We used to clone `context` here to prevent assignments from applying to
// the caller. We now purposely preserve the caller's context with its
Copy link
Contributor

Choose a reason for hiding this comment

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

// We used to clone `context` here to prevent assignments from applying to // the caller.

Honestly i dont even think that was the original reason

we cloned just so we could set in_call for that scope and its children scopes, but we tried to avoid leaking in_call = true outside of this scope
1710415

i think i was just copying some existing pattern being used in diagnostics, see other context.clone() calls in there

in retrospect your approach of setting it and making sure to reset the old value on the way out makes more sense in general, i think

@lionel- lionel- force-pushed the bugfix/assignment-in-call branch from e17c5d8 to 89c4b09 Compare November 27, 2024 16:13
@lionel- lionel- merged commit 3e6ebae into main Nov 27, 2024
6 checks passed
@lionel- lionel- deleted the bugfix/assignment-in-call branch November 27, 2024 16:20
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants