diagnostic: Add lowering/ambiguous-soft-scope detection#617
Open
diagnostic: Add lowering/ambiguous-soft-scope detection#617
lowering/ambiguous-soft-scope detection#617Conversation
7e1c8e6 to
6e452b1
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #617 +/- ##
==========================================
- Coverage 69.14% 67.51% -1.63%
==========================================
Files 51 63 +12
Lines 8662 9057 +395
==========================================
+ Hits 5989 6115 +126
- Misses 2673 2942 +269
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add a new diagnostic that warns when a variable assignment inside a `for`/`while`/`try` block at the top level shadows an existing global variable, matching the warning Julia itself emits at runtime as explained in the Julia's [soft scope manual](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#on-soft-scope): ``` global i = 0 while i < 5 i += 1 # Assignment to `i` in soft scope is ambiguous (JETLS lowering/ambiguous-soft-scope) # Variable `i` may be used before it is defined (JETLS lowering/undef-local-var) println(i) end ``` - Add `analyze_ambiguous_soft_scope!` using JuliaLowering's `is_ambiguous_local` binding flag - Add code actions: "Insert `global`" (preferred) and "Insert `local`" declarations with proper indentation - Enable soft scope semantics for notebook cells via `is_notebook_cell_uri`, suppressing this diagnostic
JuliaLang/julia#61476 allows us to remove the `insert_softscope_marker` workaround that inserted `K"softscope"` nodes into the AST and pass the `soft_scope` keword arg directly instead.
6e452b1 to
28f6586
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new diagnostic that warns when a variable assignment inside
a
for/while/tryblock at the top level shadows an existingglobal variable, matching the warning Julia itself emits at
runtime as explained in the Julia's soft scope manual:
analyze_ambiguous_soft_scope!using JuliaLowering'sis_ambiguous_localbinding flagglobal" (preferred) and"Insert
local" declarations with proper indentationis_notebook_cell_uri, suppressing this diagnosticAccompanying threes PRs on JuliaLowering side:
is_ambiguous_localin permeable scopes JuliaLang/julia#61473soft_scopekwarg toresolve_scopesJuliaLang/julia#61476is_defined_and_owned_globalJuliaLang/julia#61477