Skip to content

Conversation

@Andarist
Copy link
Contributor

fixes#61734

CopilotAI review requested due to automatic review settings June 6, 2025 18:47
@github-project-automationgithub-project-automationbot moved this to Not started in PR BacklogJun 6, 2025
@typescript-bottypescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jun 6, 2025
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes inconsistent handling of block-scoped declarations in the presence of parse errors by switching from grammarErrorOnNode to directly adding diagnostics, and adds tests to verify the TS1156 error for const, let, using, and await using declarations outside blocks.

  • Replace grammarErrorOnNode calls with diagnostics.add(createDiagnosticForNode(...)) in the checker.
  • Introduce a new compiler-test file covering parse-error scenarios for block-scoped declarations.
  • Update baselines for types, symbols, and error outputs to reflect the new diagnostic behavior.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
tests/cases/compiler/disallowedBlockScopedInPresenceOfParseErrors1.tsNew test cases for invalid block-scoped declarations with parse errors
tests/baselines/reference/disallowedBlockScopedInPresenceOfParseErrors1.typesUpdated baseline types output
tests/baselines/reference/disallowedBlockScopedInPresenceOfParseErrors1.symbolsUpdated baseline symbol output
tests/baselines/reference/disallowedBlockScopedInPresenceOfParseErrors1.errors.txtUpdated baseline error messages
src/compiler/checker.tsSwapped grammarErrorOnNode return into a direct diagnostics.add call
Comments suppressed due to low confidence (1)

src/compiler/checker.ts:52839

  • The original code returned immediately after calling grammarErrorOnNode, short-circuiting further checks. Removing the return changes control flow and may allow unintended processing after the diagnostic. Consider restoring the return to maintain the original behavior.
diagnostics.add(createDiagnosticForNode(node, Diagnostics._0_declarations_can_only_be_declared_inside_a_block, keyword)); 

…lock-scoped variables in presence of parse errors
@AndaristAndaristforce-pushed the fix/block-scoped-error-when-parse-errors branch from daad9bc to 0c24774CompareJune 6, 2025 18:48
@github-project-automationgithub-project-automationbot moved this from Not started to Needs merge in PR BacklogJun 6, 2025
@jakebaileyjakebailey merged commit fa2a0fc into microsoft:mainJun 6, 2025
32 checks passed
@github-project-automationgithub-project-automationbot moved this from Needs merge to Done in PR BacklogJun 6, 2025
@microsoftmicrosoft locked as resolved and limited conversation to collaborators Dec 9, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog BugPRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

"'const' declarations can only be declared inside a block" should be issued more aggressively

3 participants

@Andarist@jakebailey@typescript-bot