-
Notifications
You must be signed in to change notification settings - Fork 116
Fix CFG building error with parse errors in conditional branches #3551
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
base: develop
Are you sure you want to change the base?
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
…y dot Co-authored-by: nixel2007 <[email protected]>
Co-authored-by: nixel2007 <[email protected]>
Co-authored-by: nixel2007 <[email protected]>
Co-authored-by: nixel2007 <[email protected]>
|
@copilot проблема не в том, что код блок пустой, а в том, что |
Correct -
This ensures the CFG builder doesn't crash when encountering broken ParseTree structures from parsing errors. The fix prevents the |
|
@copilot может быть проверить, что в самом ifBranch есть ошибки через методы класса Trees, которые проверяют узел на ошибки? |
…al branches Instead of just checking for null codeBlock, now also check if the branch node contains parse errors using Trees.nodeContainsErrors(). This is more robust and semantically correct - explicitly checking for parse errors rather than relying on null checks alone. Co-authored-by: nixel2007 <[email protected]>
Added
This is more robust and semantically correct - explicitly checking for parse errors rather than just null checks. Commit: 7075fd2 |
Problem
When analyzing BSL code containing malformed expressions such as
"".(empty string followed by a dot), the Control Flow Graph (CFG) builder crashes with anIllegalArgumentException:This occurs when the parser creates an if/elsif/else branch with parsing errors. The invalid expression
"".breaks the ParseTree, causingcodeBlock()to returnnull. For example:The CFG builder was attempting to create edges to vertices that were never added to the graph, causing the application to crash when running diagnostics like
UnreachableCodeDiagnostic.Root Cause
In three visitor methods (
visitIfStatement,visitElsifBranch,visitElseBranch), the code flow was:blocks.enterBlock()blocks.leaveBlock()block.begin()without ensuring the vertex exists in the graphWhen the ParseTree contains parsing errors,
codeBlock()returnsnull, thevisitCodeBlockmethod is never called, so the vertex is never added to the graph viagraph.addVertex(). However, the code still tries to create edges to it, resulting in the exception.Solution
Added defensive checks and explicit vertex additions to handle broken ParseTree structures:
Trees.nodeContainsErrors()checks to detect parsing errors in branch nodescodeBlock()before visitinggraph.addVertex()calls before creating edges to ensure vertices always existThe fix now checks both conditions:
codeBlock()is nullTrees.nodeContainsErrors())If either condition is true, the codeBlock is not visited, but the vertex is still added to ensure graph integrity.
This follows the established pattern in the codebase for handling parse errors and mirrors the approach used in
visitPreproc_if.Testing
Created comprehensive test coverage in
CfgEmptyStringDotTest:All existing tests continue to pass:
UnreachableCodeDiagnosticImpact
This fix ensures CFG building is robust against incomplete or malformed code structures, preventing crashes when analyzing code with syntax errors. The language server can now gracefully handle parse errors in conditional branches without crashing.
Closes #3549
Original prompt
Fixes #3549
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.