Skip to content

fix(types): сохранять локальные значения перед вызовами - #4972

Merged
nixel2007 merged 1 commit into
developfrom
fix/local-call-boundary-types-20261118
Nov 17, 2026
Merged

nixel2007 merged 1 commit into
developfrom
fix/local-call-boundary-types-20261118

Conversation

@sfaqer

@sfaqer sfaqer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Описание

Тип локальной переменной в объявлении терял значения перед вызовами, если в теле не было общих переменных. Добавление неиспользуемой переменной модуля меняло ответ с Строка на Число | Строка.

Значения перед вызовами теперь собираются независимо от наличия общих переменных. Сброс типов самих общих переменных остаётся отдельным шагом. Добавлена регрессия без переменных модуля, прежние проверки границ вызовов и ограничение числа объединений сохранены.

Связанные задачи

Closes #4971

Чеклист

  • Ветка PR обновлена из develop
  • Отладочные, закомментированные и прочие, не имеющие смысла участки кода удалены
  • Изменения покрыты тестами
  • Обязательные действия перед коммитом выполнены (gradlew precommit)

Дополнительно

На 7f6854e: весь пакет системы типов — 2226 пройденных тестов, 84 пропущенных, 0 падений; Spotless и precommit прошли. Негативный контроль воспроизведён на develop.

Summary by CodeRabbit

  • Bug Fixes
    • Improved inferred variable types across calls, preserving values assigned before and after a call—even when no module variables are involved.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

VariableFlowPass now records variable values at each call, including in bodies without shared variables. A test checks that a local variable’s inferred declaration type includes values assigned before and after calls.

Changes: Call-boundary type tracking

Layer / File(s) Summary
Track variable values at calls
src/main/java/com/github/_1c_syntax/bsl/languageserver/types/inferencer/VariableFlowPass.java, src/test/java/com/github/_1c_syntax/bsl/languageserver/types/model/CallBoundaryUnionTest.java
VariableFlowPass now tracks changed variables for every body and unions call-boundary values into leaving, even when no shared variables exist. Shared variables are still restored to their scope-wide union after calls. The test checks that a local variable’s inferred type includes both Число and Строка.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 7f685

A local variable's declared type now keeps values assigned before calls even when the procedure has no module variables. A regression test covers this case, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title is in Russian and reads as a conventional-commit style fix: it names the fix to types (types inference) and the behavior (keeping local values before calls). The changeset is a change in Var…
Linked Issues check Passed Stack objective, [#4971]: a local variable's declared type includes values assigned before calls, with or without an unrelated module variable. Status: Addressed by PR #4972 alone (https://github.com/…
Out of Scope Changes check Passed The changes introduced by PR #4972 touch two files: VariableFlowPass.java and CallBoundaryUnionTest.java. Both files relate to the objective of [#4971].

- VariableFlowPass.java: removes the null guar…
Full details: Title check

Explanation

The title is in Russian and reads as a conventional-commit style fix: it names the fix to types (types inference) and the behavior (keeping local values before calls). The changeset is a change in VariableFlowPass that collects leaving-state changes for every body variable, so local values assigned before calls are retained even without shared module variables. A regression test in CallBoundaryUnionTest covers this. The title matches the main change and the linked issue #4971.

Full details: Linked Issues check

Explanation

Stack objective, [#4971]: a local variable's declared type includes values assigned before calls, with or without an unrelated module variable. Status: Addressed by PR #4972 alone (#4972).

Evidence:

  • VariableFlowPass.java (diff base to head): changedForLeaving is now always allocated (no longer null when no shared variables exist). applyStatements always clears and sets it. The call-boundary code in the former if (changed == null ...) branch now runs for every body. This records pre-call values into leaving regardless of shared variables.
  • The post-call reset to the entry facts still applies only to shared variables, as before.
  • CallBoundaryUnionTest.localDeclarationKeepsValuesBeforeCallsWithoutModuleVariables (new, in the head) has no module variables. It asserts the declaration types are Число and Строка. This matches the issue's negative control.
  • The existing test repeatedCallsDoNotMergeUnchangedValuesAgain and callsAcrossBranchesAndLoopIterationsKeepIncomingAndResetValues still cover call-boundary behavior and the union limits.

Gap: the new test does not assert the positional type Строка after the second assignment, which the issue also names. The existing code path was not changed for positional types, and the other tests cover related positional behavior. The positional expectation is not directly verified by the new test.

PR #4974 (uncertain, no review evidence) is not needed for this objective. Its membership does not change this result.

Full details: Out of Scope Changes check

Explanation

The changes introduced by PR #4972 touch two files: VariableFlowPass.java and CallBoundaryUnionTest.java. Both files relate to the objective of [#4971].

  • VariableFlowPass.java: removes the null guard on changedForLeaving, moves the leaving-state tracking out of the shared-variable condition, and updates Javadoc comments to match. These edits implement the objective directly.
  • CallBoundaryUnionTest.java: adds the regression test for the no-module-variable case. Test support for the objective.

No unrelated behavior change appears in the reviewed diff. Note: the change removes the conditional skip for bodies without shared variables. This can increase work per statement (changedForLeaving.set(0, n) now runs for every body). The repeated-calls test is present to guard the merge count, and the PR reports a passing suite of 2226 tests. This is a performance consideration, not an out-of-scope change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b8e5d8b and 7f6854e.

Files selected for processing: 2

  • src/main/java/com/github/_1c_syntax/bsl/languageserver/types/inferencer/VariableFlowPass.java
  • src/test/java/com/github/_1c_syntax/bsl/languageserver/types/model/CallBoundaryUnionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

@nixel2007
nixel2007 merged commit c2fa5d9 into develop Nov 17, 2026
36 of 37 checks passed
@nixel2007
nixel2007 deleted the fix/local-call-boundary-types-20261118 branch November 17, 2026 14:42
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.

Тип локальной переменной в объявлении зависит от наличия общих переменных

2 participants