Skip to content

diagnostic: Add lowering/ambiguous-soft-scope detection#617

Open
aviatesk wants to merge 2 commits intomasterfrom
avi/ambiguous-soft-scope
Open

diagnostic: Add lowering/ambiguous-soft-scope detection#617
aviatesk wants to merge 2 commits intomasterfrom
avi/ambiguous-soft-scope

Conversation

@aviatesk
Copy link
Copy Markdown
Owner

@aviatesk aviatesk commented Apr 2, 2026

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:

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

Accompanying threes PRs on JuliaLowering side:

@aviatesk aviatesk force-pushed the avi/ambiguous-soft-scope branch from 7e1c8e6 to 6e452b1 Compare April 2, 2026 11:50
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 67.51%. Comparing base (509227b) to head (28f6586).

Files with missing lines Patch % Lines
src/code-action.jl 91.66% 1 Missing ⚠️
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     
Flag Coverage Δ
JETLS.jl 69.23% <96.96%> (+0.09%) ⬆️
LSP.jl 26.57% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

aviatesk added 2 commits April 3, 2026 00:16
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.
@aviatesk aviatesk force-pushed the avi/ambiguous-soft-scope branch from 6e452b1 to 28f6586 Compare April 2, 2026 15:16
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.

1 participant