Fix internal prefix exposed in redeclared worker symbol diagnostic#44583
Fix internal prefix exposed in redeclared worker symbol diagnostic#44583notdulain wants to merge 1 commit intoballerina-platform:masterfrom
Conversation
…nostic When a named worker is declared inside a fork block, the compiler internally stores it as a lambda variable with a '0' prefix (e.g. '0worker1') to avoid name collisions in the surrounding scope. If the same worker name is declared twice within the same fork block, SymbolResolver.checkForUniqueSymbol detects the collision and reports a REDECLARED_SYMBOL diagnostic using the internal symbol name, which exposes the implementation detail to the user as: "redeclared symbol '0worker1'" Strip the WORKER_LAMBDA_VAR_PREFIX from the name before building the diagnostic so the message shows the source name the user actually wrote: "redeclared symbol 'worker1'" Adds a regression test covering duplicate worker declarations in a fork. Fixes: ballerina-platform#44468
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughA bug fix for duplicate worker name diagnostics: ChangesWorker Duplicate Diagnostic Normalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
CI Failures — Both Unrelated to This PRThis PR only touches 🐧 Ubuntu — Pre-existing master breakage (Stdlib Level failures)All stdlib level failures (levels 1, 7, 8, 10) trace to a single root cause:
This will affect every PR targeting
🪟 Windows — Flaky shell integration testThis is a known JLine REPL terminal pipe-broken flake on Windows, completely unrelated to the symbol resolver changes in this PR. Re-running the job should clear it. |
Purpose
Fixes #44468
When a named worker is declared inside a
forkblock, the compiler internally stores it as a lambda variable with a0prefix (e.g.0worker1) to avoid name collisions in thesurrounding scope. If the same worker name is declared twice within the same
fork,SymbolResolver.checkForUniqueSymboldetects the collision and reports aREDECLARED_SYMBOLdiagnostic using the internal symbol name, leaking the implementation detail to the user:
error: redeclared symbol '0worker1'
The user-facing diagnostic should reference the source name they actually wrote (
worker1), not the internal lambda variable name.Reproducer
Approach
In SymbolResolver.checkForUniqueSymbol, before constructing the REDECLARED_SYMBOL (and UNSUPPORTED_REMOTE_METHOD_NAME_IN_SCOPE) diagnostic, strip the WORKER_LAMBDA_VAR_PREFIX ("0")
from the symbol name when it is present. This keeps the internal naming scheme intact for symbol resolution while ensuring the user-facing message shows the original source name:
error: redeclared symbol 'worker1'
The change is local to the diagnostic construction path and does not affect symbol lookup, scoping, or codegen.
Samples
N/A — diagnostic message fix.
Remarks
None
Check List
Summary
This pull request improves the clarity of compiler diagnostic messages for duplicate worker declarations in fork blocks. When multiple workers with the same name are declared within a fork, the compiler internally uses a lambda-variable prefix for tracking purposes. Previously, this implementation detail would leak into error messages, showing users internal names like "0worker1" instead of the source names they wrote.
Changes
Compiler Logic (SymbolResolver.java)
Test Coverage
Impact
Users will now receive clearer diagnostic messages for duplicate worker declarations, with error messages referencing the actual symbol names from their source code rather than internal compiler representations.