diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go index 9ad9476d0a..62954d50a7 100644 --- a/internal/checker/grammarchecks.go +++ b/internal/checker/grammarchecks.go @@ -37,7 +37,7 @@ func (c *Checker) grammarErrorAtPos(nodeForSourceFile *ast.Node, start int, leng func (c *Checker) grammarErrorOnNode(node *ast.Node, message *diagnostics.Message, args ...any) bool { sourceFile := ast.GetSourceFileOfNode(node) if !c.hasParseDiagnostics(sourceFile) { - c.diagnostics.Add(NewDiagnosticForNode(node, message, args...)) + c.error(node, message, args...) return true } return false @@ -1841,7 +1841,7 @@ func (c *Checker) checkGrammarForDisallowedBlockScopedVariableStatement(node *as default: panic("Unknown BlockScope flag") } - return c.grammarErrorOnNode(node.AsNode(), diagnostics.X_0_declarations_can_only_be_declared_inside_a_block, keyword) + c.error(node.AsNode(), diagnostics.X_0_declarations_can_only_be_declared_inside_a_block, keyword) } } diff --git a/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt b/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt index 7670e9c436..9839a817fc 100644 --- a/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt @@ -1,19 +1,25 @@ +disallowedBlockScopedInPresenceOfParseErrors1.ts(5,5): error TS1156: 'const' declarations can only be declared inside a block. disallowedBlockScopedInPresenceOfParseErrors1.ts(6,17): error TS2454: Variable 'e' is used before being assigned. disallowedBlockScopedInPresenceOfParseErrors1.ts(8,1): error TS1128: Declaration or statement expected. +disallowedBlockScopedInPresenceOfParseErrors1.ts(12,5): error TS1156: 'let' declarations can only be declared inside a block. disallowedBlockScopedInPresenceOfParseErrors1.ts(13,17): error TS2454: Variable 'e' is used before being assigned. disallowedBlockScopedInPresenceOfParseErrors1.ts(15,1): error TS1128: Declaration or statement expected. +disallowedBlockScopedInPresenceOfParseErrors1.ts(21,5): error TS1156: 'using' declarations can only be declared inside a block. disallowedBlockScopedInPresenceOfParseErrors1.ts(22,17): error TS2454: Variable 'e' is used before being assigned. disallowedBlockScopedInPresenceOfParseErrors1.ts(24,1): error TS1128: Declaration or statement expected. +disallowedBlockScopedInPresenceOfParseErrors1.ts(30,5): error TS1156: 'await using' declarations can only be declared inside a block. disallowedBlockScopedInPresenceOfParseErrors1.ts(31,17): error TS2454: Variable 'e' is used before being assigned. disallowedBlockScopedInPresenceOfParseErrors1.ts(33,1): error TS1128: Declaration or statement expected. -==== disallowedBlockScopedInPresenceOfParseErrors1.ts (8 errors) ==== +==== disallowedBlockScopedInPresenceOfParseErrors1.ts (12 errors) ==== // https://github.com/microsoft/TypeScript/issues/61734 function f1() { if (1 > 0) const e = 3; + ~~~~~~~~~~~~ +!!! error TS1156: 'const' declarations can only be declared inside a block. console.log(e); ~ !!! error TS2454: Variable 'e' is used before being assigned. @@ -25,6 +31,8 @@ disallowedBlockScopedInPresenceOfParseErrors1.ts(33,1): error TS1128: Declaratio function f2() { if (1 > 0) let e = 3; + ~~~~~~~~~~ +!!! error TS1156: 'let' declarations can only be declared inside a block. console.log(e); ~ !!! error TS2454: Variable 'e' is used before being assigned. @@ -38,6 +46,8 @@ disallowedBlockScopedInPresenceOfParseErrors1.ts(33,1): error TS1128: Declaratio function f3() { if (1 > 0) using e = resource; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1156: 'using' declarations can only be declared inside a block. console.log(e); ~ !!! error TS2454: Variable 'e' is used before being assigned. @@ -51,6 +61,8 @@ disallowedBlockScopedInPresenceOfParseErrors1.ts(33,1): error TS1128: Declaratio async function f4() { if (1 > 0) await using e = asyncResource; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1156: 'await using' declarations can only be declared inside a block. console.log(e); ~ !!! error TS2454: Variable 'e' is used before being assigned. diff --git a/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt.diff deleted file mode 100644 index 85cd19ea87..0000000000 --- a/testdata/baselines/reference/submodule/compiler/disallowedBlockScopedInPresenceOfParseErrors1.errors.txt.diff +++ /dev/null @@ -1,56 +0,0 @@ ---- old.disallowedBlockScopedInPresenceOfParseErrors1.errors.txt -+++ new.disallowedBlockScopedInPresenceOfParseErrors1.errors.txt -@@= skipped -0, +0 lines =@@ --disallowedBlockScopedInPresenceOfParseErrors1.ts(5,5): error TS1156: 'const' declarations can only be declared inside a block. - disallowedBlockScopedInPresenceOfParseErrors1.ts(6,17): error TS2454: Variable 'e' is used before being assigned. - disallowedBlockScopedInPresenceOfParseErrors1.ts(8,1): error TS1128: Declaration or statement expected. --disallowedBlockScopedInPresenceOfParseErrors1.ts(12,5): error TS1156: 'let' declarations can only be declared inside a block. - disallowedBlockScopedInPresenceOfParseErrors1.ts(13,17): error TS2454: Variable 'e' is used before being assigned. - disallowedBlockScopedInPresenceOfParseErrors1.ts(15,1): error TS1128: Declaration or statement expected. --disallowedBlockScopedInPresenceOfParseErrors1.ts(21,5): error TS1156: 'using' declarations can only be declared inside a block. - disallowedBlockScopedInPresenceOfParseErrors1.ts(22,17): error TS2454: Variable 'e' is used before being assigned. - disallowedBlockScopedInPresenceOfParseErrors1.ts(24,1): error TS1128: Declaration or statement expected. --disallowedBlockScopedInPresenceOfParseErrors1.ts(30,5): error TS1156: 'await using' declarations can only be declared inside a block. - disallowedBlockScopedInPresenceOfParseErrors1.ts(31,17): error TS2454: Variable 'e' is used before being assigned. - disallowedBlockScopedInPresenceOfParseErrors1.ts(33,1): error TS1128: Declaration or statement expected. - - --==== disallowedBlockScopedInPresenceOfParseErrors1.ts (12 errors) ==== -+==== disallowedBlockScopedInPresenceOfParseErrors1.ts (8 errors) ==== - // https://github.com/microsoft/TypeScript/issues/61734 - - function f1() { - if (1 > 0) - const e = 3; -- ~~~~~~~~~~~~ --!!! error TS1156: 'const' declarations can only be declared inside a block. - console.log(e); - ~ - !!! error TS2454: Variable 'e' is used before being assigned. -@@= skipped -30, +24 lines =@@ - function f2() { - if (1 > 0) - let e = 3; -- ~~~~~~~~~~ --!!! error TS1156: 'let' declarations can only be declared inside a block. - console.log(e); - ~ - !!! error TS2454: Variable 'e' is used before being assigned. -@@= skipped -15, +13 lines =@@ - function f3() { - if (1 > 0) - using e = resource; -- ~~~~~~~~~~~~~~~~~~~ --!!! error TS1156: 'using' declarations can only be declared inside a block. - console.log(e); - ~ - !!! error TS2454: Variable 'e' is used before being assigned. -@@= skipped -15, +13 lines =@@ - async function f4() { - if (1 > 0) - await using e = asyncResource; -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1156: 'await using' declarations can only be declared inside a block. - console.log(e); - ~ - !!! error TS2454: Variable 'e' is used before being assigned. \ No newline at end of file