Skip to content

Fix CFG builder crash on preprocessor directives spanning elsif boundaries#3823

Draft
Copilot wants to merge 2 commits intodevelopfrom
copilot/fix-diagnostic-computation-error-again
Draft

Fix CFG builder crash on preprocessor directives spanning elsif boundaries#3823
Copilot wants to merge 2 commits intodevelopfrom
copilot/fix-diagnostic-computation-error-again

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Both UnreachableCode and AllFunctionPathMustHaveReturn diagnostics throw Diagnostic computation error when preprocessor #Если/#КонецЕсли spans across ИначеЕсли boundaries, causing the CFG builder's block stack to become unbalanced.

Pattern that triggers the crash:

Если КлассОМ = "ПЛАНОБМЕНА" Тогда
    Менеджер = ПланыОбмена;
#Если НЕ МобильноеПриложениеСервер Тогда
ИначеЕсли КлассОМ = "ОТЧЕТ" Тогда
    Менеджер = Отчеты;
#КонецЕсли
КонецЕсли;

visitPreproc_if enters two blocks that visitPreproc_endif never leaves (the #КонецЕсли is in a different codeBlock), corrupting the stack → NoSuchElementException / FlowGraphLinkException.

Changes

  • CfgBuildingParseTreeVisitor.visitPreproc_if() — added hasMatchingEndIfInSameCodeBlock() guard; when unbalanced, skip CFG node creation and fall back to super.visitPreproc_if(ctx)
  • hasMatchingEndIfInSameCodeBlock() — new helper that walks sibling statements in the enclosing codeBlock, tracking #Если/#КонецЕсли nesting depth to verify balance
  • UnreachableCodeDiagnosticTest — 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:

[ERROR] [diagnostic-computer] [com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticComputer]: Diagnostic computation error.
File: file:///.../адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl
Diagnostic: Either [
  left = UnreachableCode
  right = null
]

Пример кода

Процедура Ожидание с ранним Возврат и заведомо недостижимым кодом:

Процедура Ожидание(Компонента, Секунд) Экспорт

	// Нетиповое{ ПервыйБИТ Латышева Н.А.  12.03.2024 VTRD-724
	// #ОтказОтSleep
	Возврат;
	// Нетиповое} ПервыйБИТ Латышева Н.А.  12.03.2024 VTRD-724	
	
	Если ТипЗнч(Компонента) = Тип("ОбработкаОбъект.адаптер_КомпонентаRabbitMQ") Тогда
		Компонента.Ожидание(Секунд * 1000);
	Иначе
		Компонента.Sleep(Секунд * 1000);
	КонецЕсли;
	
КонецПроцедуры

Скриншоты

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by org.ehcache.impl.internal.concurrent.ThreadLocalRandomUtil (jar:nested:/C:/Users/ikarl/AppData/Roaming/Cursor/User/globalStorage/1c-syntax.language-1c-bsl/bsl-language-server/v0.28.4/bsl-language-server/app/bsl-language-server-0.28.4-exec.jar/!BOOT-INF/lib/ehcache-3.11.1.jar!/)
WARNING: Please consider reporting this to the maintainers of class org.ehcache.impl.internal.concurrent.ThreadLocalRandomUtil
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
[Warn  - 11:31:10] [WARN - 2026-02-17T08:31:04.567399600Z] [compute-configuration-7] [com.github._1c_syntax.bsl.reader.common.converter.ValueTypeConverter]: Parsing error due to unknown value type v8ui:ChartType. Please, create issue using link https://github.com/1c-syntax/mdclasses/issues/new?labels=bug&title=%5BBUG%5D%20Unknown%20valueType%20%5Bv8ui:ChartType%5D
[Warn  - 11:31:10] [WARN - 2026-02-17T08:31:04.850074800Z] [compute-configuration-12] [com.github._1c_syntax.bsl.reader.common.converter.ValueTypeConverter]: Parsing error due to unknown value type v8ui:HorizontalAlign. Please, create issue using link https://github.com/1c-syntax/mdclasses/issues/new?labels=bug&title=%5BBUG%5D%20Unknown%20valueType%20%5Bv8ui:HorizontalAlign%5D
[Warn  - 11:31:13] [WARN - 2026-02-17T08:31:06.703016400Z] [compute-configuration-6] [com.github._1c_syntax.bsl.reader.common.converter.ValueTypeConverter]: Parsing error due to unknown value type d7p1:FlowchartContextType. Please, create issue using link https://github.com/1c-syntax/mdclasses/issues/new?labels=bug&title=%5BBUG%5D%20Unknown%20valueType%20%5Bd7p1:FlowchartContextType%5D
[Error - 11:31:27] [ERROR - 2026-02-17T08:31:12.943362400Z] [diagnostic-computer-13] [com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticComputer]: Diagnostic computation error.
File: file:///C:/Users/ikarl/git/git.ventra.local/Ventra-1C/bit.finance/src/cfe/БИТАдаптер/CommonModules/адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl
Diagnostic: Either [
  left = AllFunctionPathMustHaveReturn
  right = null
]
[Error - 11:31:29] [ERROR - 2026-02-17T08:31:12.970360400Z] [diagnostic-computer-26] [com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticComputer]: Diagnostic computation error.
File: file:///C:/Users/ikarl/git/git.ventra.local/Ventra-1C/bit.finance/src/cfe/БИТАдаптер/CommonModules/адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl
Diagnostic: Either [
  left = UnreachableCode
  right = null
]
[Error - 11:47:43] [ERROR - 2026-02-17T08:47:43.252984900Z] [diagnostic-computer-45] [com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticComputer]: Diagnostic computation error.
File: file:///C:/Users/ikarl/git/git.ventra.local/Ventra-1C/bit.finance/src/cfe/БИТАдаптер/CommonModules/адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl
Diagnostic: Either [
  left = AllFunctionPathMustHaveReturn
  right = null
]
[Error - 11:47:43] [ERROR - 2026-02-17T08:47:43.277982Z] [diagnostic-computer-48] [com.github._1c_syntax.bsl.languageserver.context.computer.DiagnosticComputer]: Diagnostic computation error.
File: file:///C:/Users/ikarl/git/git.ventra.local/Ventra-1C/bit.finance/src/cfe/БИТАдаптер/CommonModules/адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl
Diagnostic: Either [
  left = UnreachableCode
  right = null
]

Дополнительная информация

  • Код после Возврат; (стр. 684) действительно недостижим.
  • BSLLS вместо отчёта UnreachableCode генерирует Diagnostic computation error.
  • Воспроизводится в VS Code и SonarQube.
  • Файл: src/cfe/БИТАдаптер/CommonModules/адаптер_ОбщегоНазначенияСервер/Ext/Module.bsl.

[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.

…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
Copilot AI requested a review from nixel2007 February 17, 2026 18:23
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.

[BUG] Diagnostic computation error при проверке UnreachableCode

2 participants