Fix CFG builder crash on preprocessor directives spanning elsif boundaries#3823
Draft
Fix CFG builder crash on preprocessor directives spanning elsif boundaries#3823
Conversation
…boundaries When a statement-level #Если in one elsif branch's codeBlock does not have a matching #КонецЕсли in the same codeBlock (because it spans across elsif boundaries), the CFG builder's block stack becomes unbalanced, leading to NoSuchElementException or FlowGraphLinkException. Add hasMatchingEndIfInSameCodeBlock() check to visitPreproc_if() to detect unbalanced preprocessor blocks and skip CFG graph manipulation for them, falling back to simple child visiting instead. Fixes #3821 Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix diagnostic computation error for UnreachableCode
Fix CFG builder crash on preprocessor directives spanning elsif boundaries
Feb 17, 2026
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.
Both
UnreachableCodeandAllFunctionPathMustHaveReturndiagnostics throwDiagnostic computation errorwhen preprocessor#Если/#КонецЕслиspans acrossИначеЕслиboundaries, causing the CFG builder's block stack to become unbalanced.Pattern that triggers the crash:
visitPreproc_ifenters two blocks thatvisitPreproc_endifnever leaves (the#КонецЕслиis in a different codeBlock), corrupting the stack →NoSuchElementException/FlowGraphLinkException.Changes
CfgBuildingParseTreeVisitor.visitPreproc_if()— addedhasMatchingEndIfInSameCodeBlock()guard; when unbalanced, skip CFG node creation and fall back tosuper.visitPreproc_if(ctx)hasMatchingEndIfInSameCodeBlock()— new helper that walks sibling statements in the enclosing codeBlock, tracking#Если/#КонецЕслиnesting depth to verify balanceUnreachableCodeDiagnosticTest— added test with the exact crash pattern (preprocessor wrapping elsif branches + earlyВозврат)Original prompt
This section details on the original issue you should resolve
<issue_title>[BUG] Diagnostic computation error при проверке UnreachableCode</issue_title>
<issue_description>## Диагностика
UnreachableCode
Версия
BSLLS v0.28.4 (расширение 1c-syntax.language-1c-bsl для VS Code)
Описание ошибки диагностики
При анализе модуля адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl вместо результата проверки UnreachableCode возникает Diagnostic computation error:
Пример кода
Процедура Ожидание с ранним Возврат и заведомо недостижимым кодом:
Скриншоты
Дополнительная информация
[Diagnostic error.z...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.