From 4994ad6492ffa4190c148225b137568d6507a754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 4 Oct 2025 00:11:04 +0200 Subject: [PATCH 1/3] Port "`arguments` should not be allowed in class static block" Co-authored-by: Zzzen --- internal/checker/checker.go | 26 +++---- ...izerOrStaticInitializationBlock.errors.txt | 20 +++++- ...rStaticInitializationBlock.errors.txt.diff | 71 ------------------- ...itializerOrStaticInitializationBlock.types | 34 ++++----- ...izerOrStaticInitializationBlock.types.diff | 68 ++++++++++++++++-- .../decoratorUsedBeforeDeclaration.errors.txt | 10 ++- ...ratorUsedBeforeDeclaration.errors.txt.diff | 30 ++------ .../conformance/classStaticBlock6.errors.txt | 6 +- .../classStaticBlock6.errors.txt.diff | 24 ++----- 9 files changed, 132 insertions(+), 157 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt.diff diff --git a/internal/checker/checker.go b/internal/checker/checker.go index f0323ed53d..ff35ed69b6 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -10583,7 +10583,7 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { return c.errorType } if symbol == c.argumentsSymbol { - if c.isInPropertyInitializerOrClassStaticBlock(node) { + if c.isInPropertyInitializerOrClassStaticBlock(node, true /*ignoreArrowFunctions*/) { c.error(node, diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks) return c.errorType } @@ -11215,7 +11215,7 @@ func (c *Checker) checkPropertyNotUsedBeforeDeclaration(prop *ast.Symbol, node * } var diagnostic *ast.Diagnostic declarationName := right.Text() - if c.isInPropertyInitializerOrClassStaticBlock(node) && + if c.isInPropertyInitializerOrClassStaticBlock(node, false /*ignoreArrowFunctions*/) && !c.isOptionalPropertyDeclaration(valueDeclaration) && !(ast.IsAccessExpression(node) && ast.IsAccessExpression(node.Expression())) && !c.isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) && @@ -13136,25 +13136,19 @@ func (c *Checker) checkShorthandPropertyAssignment(node *ast.Node, inDestructuri return expressionType } -func (c *Checker) isInPropertyInitializerOrClassStaticBlock(node *ast.Node) bool { +func (c *Checker) isInPropertyInitializerOrClassStaticBlock(node *ast.Node, ignoreArrowFunctions bool) bool { return ast.FindAncestorOrQuit(node, func(node *ast.Node) ast.FindAncestorResult { switch node.Kind { - case ast.KindPropertyDeclaration: + case ast.KindPropertyDeclaration, ast.KindClassStaticBlockDeclaration: return ast.FindAncestorTrue - case ast.KindPropertyAssignment, ast.KindMethodDeclaration, ast.KindGetAccessor, ast.KindSetAccessor, ast.KindSpreadAssignment, - ast.KindComputedPropertyName, ast.KindTemplateSpan, ast.KindJsxExpression, ast.KindJsxAttribute, ast.KindJsxAttributes, - ast.KindJsxSpreadAttribute, ast.KindJsxOpeningElement, ast.KindExpressionWithTypeArguments, ast.KindHeritageClause: - return ast.FindAncestorFalse - case ast.KindArrowFunction, ast.KindExpressionStatement: - if ast.IsBlock(node.Parent) && ast.IsClassStaticBlockDeclaration(node.Parent.Parent) { - return ast.FindAncestorTrue - } + case ast.KindTypeQuery, ast.KindJsxClosingElement: return ast.FindAncestorQuit + case ast.KindArrowFunction: + return core.IfElse(ignoreArrowFunctions, ast.FindAncestorFalse, ast.FindAncestorQuit) + case ast.KindBlock: + return core.IfElse(ast.IsFunctionLikeDeclaration(node.Parent) && node.Parent.Kind != ast.KindArrowFunction, ast.FindAncestorQuit, ast.FindAncestorFalse) default: - if ast.IsExpressionNode(node) { - return ast.FindAncestorFalse - } - return ast.FindAncestorQuit + return ast.FindAncestorFalse } }) != nil } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt index 47d75a9136..f382004c03 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt @@ -2,11 +2,17 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(3,10): error argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(9,10): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(15,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. +argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(33,16): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. +argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(40,7): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. +argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(42,16): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(66,6): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. +argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(77,9): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. +argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(96,26): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. +argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(102,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. -==== argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts (6 errors) ==== +==== argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts (12 errors) ==== function A() { return class T { a = arguments @@ -48,6 +54,8 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error function D() { return class T { a = () => arguments // should error + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. } } @@ -55,8 +63,12 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error return class T { a = () => { arguments; // should error + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. const b = () => { return arguments; // should error + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. } function f() { @@ -96,6 +108,8 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error !!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. while(1) { arguments // should error + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. } } } @@ -115,12 +129,16 @@ argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error function D5() { return class T { a = (() => { return arguments; })() // should error + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. } } function D6() { return class T { a = (x = arguments) => {} // should error + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. } } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt.diff deleted file mode 100644 index e541265802..0000000000 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt.diff +++ /dev/null @@ -1,71 +0,0 @@ ---- old.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt -+++ new.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.errors.txt -@@= skipped -1, +1 lines =@@ - argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(9,10): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(15,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(21,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. --argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(33,16): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. --argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(40,7): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. --argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(42,16): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(66,6): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. - argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(75,7): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. --argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(77,9): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. --argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(96,26): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. --argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts(102,15): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. -- -- --==== argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts (12 errors) ==== -+ -+ -+==== argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.ts (6 errors) ==== - function A() { - return class T { - a = arguments -@@= skipped -52, +46 lines =@@ - function D() { - return class T { - a = () => arguments // should error -- ~~~~~~~~~ --!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - } - } - -@@= skipped -9, +7 lines =@@ - return class T { - a = () => { - arguments; // should error -- ~~~~~~~~~ --!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - const b = () => { - return arguments; // should error -- ~~~~~~~~~ --!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - } - - function f() { -@@= skipped -45, +41 lines =@@ - !!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - while(1) { - arguments // should error -- ~~~~~~~~~ --!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - } - } - } -@@= skipped -21, +19 lines =@@ - function D5() { - return class T { - a = (() => { return arguments; })() // should error -- ~~~~~~~~~ --!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - } - } - - function D6() { - return class T { - a = (x = arguments) => {} // should error -- ~~~~~~~~~ --!!! error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. - } - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types index 2a09231ab2..6d0798d90a 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types @@ -81,9 +81,9 @@ function D() { >T : typeof T a = () => arguments // should error ->a : () => IArguments ->() => arguments : () => IArguments ->arguments : IArguments +>a : () => any +>() => arguments : () => any +>arguments : any } } @@ -99,14 +99,14 @@ function D1() { >() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void arguments; // should error ->arguments : IArguments +>arguments : any const b = () => { ->b : () => IArguments ->() => { return arguments; // should error } : () => IArguments +>b : () => any +>() => { return arguments; // should error } : () => any return arguments; // should error ->arguments : IArguments +>arguments : any } function f() { @@ -175,7 +175,7 @@ function D3() { >1 : 1 arguments // should error ->arguments : IArguments +>arguments : any } } } @@ -208,11 +208,11 @@ function D5() { >T : typeof T a = (() => { return arguments; })() // should error ->a : IArguments ->(() => { return arguments; })() : IArguments ->(() => { return arguments; }) : () => IArguments ->() => { return arguments; } : () => IArguments ->arguments : IArguments +>a : any +>(() => { return arguments; })() : any +>(() => { return arguments; }) : () => any +>() => { return arguments; } : () => any +>arguments : any } } @@ -224,10 +224,10 @@ function D6() { >T : typeof T a = (x = arguments) => {} // should error ->a : (x?: IArguments) => void ->(x = arguments) => {} : (x?: IArguments) => void ->x : IArguments ->arguments : IArguments +>a : (x?: any) => void +>(x = arguments) => {} : (x?: any) => void +>x : any +>arguments : any } } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff index 5df6e3a49d..e820f62202 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff @@ -1,11 +1,65 @@ --- old.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types +++ new.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types -@@= skipped -174, +174 lines =@@ - >1 : 1 +@@= skipped -80, +80 lines =@@ + >T : typeof T - arguments // should error -->arguments : any -+>arguments : IArguments + a = () => arguments // should error +->a : () => IArguments +->() => arguments : () => IArguments +->arguments : IArguments ++>a : () => any ++>() => arguments : () => any ++>arguments : any + } + } + +@@= skipped -18, +18 lines =@@ + >() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void + + arguments; // should error +->arguments : IArguments ++>arguments : any + + const b = () => { +->b : () => IArguments +->() => { return arguments; // should error } : () => IArguments ++>b : () => any ++>() => { return arguments; // should error } : () => any + + return arguments; // should error +->arguments : IArguments ++>arguments : any } - } - } \ No newline at end of file + + function f() { +@@= skipped -109, +109 lines =@@ + >T : typeof T + + a = (() => { return arguments; })() // should error +->a : IArguments +->(() => { return arguments; })() : IArguments +->(() => { return arguments; }) : () => IArguments +->() => { return arguments; } : () => IArguments +->arguments : IArguments ++>a : any ++>(() => { return arguments; })() : any ++>(() => { return arguments; }) : () => any ++>() => { return arguments; } : () => any ++>arguments : any + } + } + +@@= skipped -16, +16 lines =@@ + >T : typeof T + + a = (x = arguments) => {} // should error +->a : (x?: IArguments) => void +->(x = arguments) => {} : (x?: IArguments) => void +->x : IArguments +->arguments : IArguments ++>a : (x?: any) => void ++>(x = arguments) => {} : (x?: any) => void ++>x : any ++>arguments : any + } + } diff --git a/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt b/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt index a5829d2097..566aa80934 100644 --- a/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt @@ -3,10 +3,12 @@ decoratorUsedBeforeDeclaration.ts(1,9): error TS2450: Enum 'Enum' used before it decoratorUsedBeforeDeclaration.ts(2,7): error TS2450: Enum 'Enum' used before its declaration. decoratorUsedBeforeDeclaration.ts(4,4): error TS2448: Block-scoped variable 'lambda' used before its declaration. decoratorUsedBeforeDeclaration.ts(4,11): error TS2450: Enum 'Enum' used before its declaration. +decoratorUsedBeforeDeclaration.ts(4,16): error TS2729: Property 'No' is used before its initialization. decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before its declaration. +decoratorUsedBeforeDeclaration.ts(5,14): error TS2729: Property 'No' is used before its initialization. -==== decoratorUsedBeforeDeclaration.ts (6 errors) ==== +==== decoratorUsedBeforeDeclaration.ts (8 errors) ==== @lambda(Enum.No) ~~~~~~ !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. @@ -26,10 +28,16 @@ decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before it ~~~~ !!! error TS2450: Enum 'Enum' used before its declaration. !!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. + ~~ +!!! error TS2729: Property 'No' is used before its initialization. +!!! related TS2728 decoratorUsedBeforeDeclaration.ts:36:3: 'No' is declared here. @deco(Enum.No) ~~~~ !!! error TS2450: Enum 'Enum' used before its declaration. !!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. + ~~ +!!! error TS2729: Property 'No' is used before its initialization. +!!! related TS2728 decoratorUsedBeforeDeclaration.ts:36:3: 'No' is declared here. greeting: string; constructor(message: string) { diff --git a/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt.diff index 56dfc89192..e640f2bdab 100644 --- a/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt.diff +++ b/testdata/baselines/reference/submodule/compiler/decoratorUsedBeforeDeclaration.errors.txt.diff @@ -1,12 +1,9 @@ --- old.decoratorUsedBeforeDeclaration.errors.txt +++ new.decoratorUsedBeforeDeclaration.errors.txt -@@= skipped -2, +2 lines =@@ - decoratorUsedBeforeDeclaration.ts(2,7): error TS2450: Enum 'Enum' used before its declaration. - decoratorUsedBeforeDeclaration.ts(4,4): error TS2448: Block-scoped variable 'lambda' used before its declaration. - decoratorUsedBeforeDeclaration.ts(4,11): error TS2450: Enum 'Enum' used before its declaration. --decoratorUsedBeforeDeclaration.ts(4,16): error TS2729: Property 'No' is used before its initialization. +@@= skipped -5, +5 lines =@@ + decoratorUsedBeforeDeclaration.ts(4,16): error TS2729: Property 'No' is used before its initialization. decoratorUsedBeforeDeclaration.ts(5,9): error TS2450: Enum 'Enum' used before its declaration. --decoratorUsedBeforeDeclaration.ts(5,14): error TS2729: Property 'No' is used before its initialization. + decoratorUsedBeforeDeclaration.ts(5,14): error TS2729: Property 'No' is used before its initialization. -decoratorUsedBeforeDeclaration.ts(12,4): error TS2448: Block-scoped variable 'lambda' used before its declaration. -decoratorUsedBeforeDeclaration.ts(12,11): error TS2450: Enum 'Enum' used before its declaration. -decoratorUsedBeforeDeclaration.ts(13,9): error TS2450: Enum 'Enum' used before its declaration. @@ -20,28 +17,11 @@ -==== decoratorUsedBeforeDeclaration.ts (16 errors) ==== + + -+==== decoratorUsedBeforeDeclaration.ts (6 errors) ==== ++==== decoratorUsedBeforeDeclaration.ts (8 errors) ==== @lambda(Enum.No) ~~~~~~ !!! error TS2448: Block-scoped variable 'lambda' used before its declaration. -@@= skipped -33, +23 lines =@@ - ~~~~ - !!! error TS2450: Enum 'Enum' used before its declaration. - !!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. -- ~~ --!!! error TS2729: Property 'No' is used before its initialization. --!!! related TS2728 decoratorUsedBeforeDeclaration.ts:36:3: 'No' is declared here. - @deco(Enum.No) - ~~~~ - !!! error TS2450: Enum 'Enum' used before its declaration. - !!! related TS2728 decoratorUsedBeforeDeclaration.ts:35:6: 'Enum' is declared here. -- ~~ --!!! error TS2729: Property 'No' is used before its initialization. --!!! related TS2728 decoratorUsedBeforeDeclaration.ts:36:3: 'No' is declared here. - greeting: string; - - constructor(message: string) { -@@= skipped -17, +11 lines =@@ +@@= skipped -47, +39 lines =@@ } @lambda(Enum.No) diff --git a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt index a576260cf9..7e8a0fa613 100644 --- a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt @@ -13,9 +13,10 @@ classStaticBlock6.ts(42,18): error TS1109: Expression expected. classStaticBlock6.ts(46,22): error TS1109: Expression expected. classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. classStaticBlock6.ts(66,14): error TS2729: Property 'b' is used before its initialization. +classStaticBlock6.ts(69,18): error TS2729: Property 'b' is used before its initialization. -==== classStaticBlock6.ts (15 errors) ==== +==== classStaticBlock6.ts (16 errors) ==== class B { static a = 1; } @@ -116,6 +117,9 @@ classStaticBlock6.ts(66,14): error TS2729: Property 'b' is used before its initi let b: typeof this.b; // ok if (1) { this.b; // should error + ~ +!!! error TS2729: Property 'b' is used before its initialization. +!!! related TS2728 classStaticBlock6.ts:73:12: 'b' is declared here. } } diff --git a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt.diff b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt.diff index c3738627fd..5e113bc0ec 100644 --- a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt.diff +++ b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.errors.txt.diff @@ -8,17 +8,15 @@ classStaticBlock6.ts(46,22): error TS1109: Expression expected. classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in property initializers or class static initialization blocks. classStaticBlock6.ts(66,14): error TS2729: Property 'b' is used before its initialization. --classStaticBlock6.ts(69,18): error TS2729: Property 'b' is used before its initialization. -- -- + classStaticBlock6.ts(69,18): error TS2729: Property 'b' is used before its initialization. + + -==== classStaticBlock6.ts (17 errors) ==== -+ -+ -+==== classStaticBlock6.ts (15 errors) ==== ++==== classStaticBlock6.ts (16 errors) ==== class B { static a = 1; } -@@= skipped -77, +75 lines =@@ +@@= skipped -77, +76 lines =@@ async function ff () { arguments; @@ -26,14 +24,4 @@ -!!! error TS2522: The 'arguments' object cannot be referenced in an async function or method in ES5. Consider using a standard function or method. await; ~ - !!! error TS1109: Expression expected. -@@= skipped -33, +31 lines =@@ - let b: typeof this.b; // ok - if (1) { - this.b; // should error -- ~ --!!! error TS2729: Property 'b' is used before its initialization. --!!! related TS2728 classStaticBlock6.ts:73:12: 'b' is declared here. - } - } - \ No newline at end of file + !!! error TS1109: Expression expected. \ No newline at end of file From e2cd9c6370187b5f4db52a7cce3aaa5421ba3b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 4 Oct 2025 09:46:18 +0200 Subject: [PATCH 2/3] check without error type --- internal/checker/checker.go | 1 - ...itializerOrStaticInitializationBlock.types | 60 ++++++------ ...izerOrStaticInitializationBlock.types.diff | 97 ++++++++++--------- .../conformance/classStaticBlock6.types | 4 +- .../conformance/classStaticBlock6.types.diff | 20 ++++ 5 files changed, 103 insertions(+), 79 deletions(-) create mode 100644 testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff diff --git a/internal/checker/checker.go b/internal/checker/checker.go index ff35ed69b6..979786d610 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -10585,7 +10585,6 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { if symbol == c.argumentsSymbol { if c.isInPropertyInitializerOrClassStaticBlock(node, true /*ignoreArrowFunctions*/) { c.error(node, diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks) - return c.errorType } return c.getTypeOfSymbol(symbol) } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types index 6d0798d90a..d4a10110e0 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types @@ -9,8 +9,8 @@ function A() { >T : typeof T a = arguments ->a : any ->arguments : any +>a : IArguments +>arguments : IArguments } } @@ -23,8 +23,8 @@ function A1() { >T : typeof T a = arguments ->a : any ->arguments : any +>a : IArguments +>arguments : IArguments } } @@ -36,10 +36,10 @@ function B() { >T : typeof T a = { b: arguments } ->a : { b: any; } ->{ b: arguments } : { b: any; } ->b : any ->arguments : any +>a : { b: IArguments; } +>{ b: arguments } : { b: IArguments; } +>b : IArguments +>arguments : IArguments } } @@ -52,10 +52,10 @@ function B1() { >T : typeof T a = { b: arguments } ->a : { b: any; } ->{ b: arguments } : { b: any; } ->b : any ->arguments : any +>a : { b: IArguments; } +>{ b: arguments } : { b: IArguments; } +>b : IArguments +>arguments : IArguments } } @@ -81,9 +81,9 @@ function D() { >T : typeof T a = () => arguments // should error ->a : () => any ->() => arguments : () => any ->arguments : any +>a : () => IArguments +>() => arguments : () => IArguments +>arguments : IArguments } } @@ -99,14 +99,14 @@ function D1() { >() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void arguments; // should error ->arguments : any +>arguments : IArguments const b = () => { ->b : () => any ->() => { return arguments; // should error } : () => any +>b : () => IArguments +>() => { return arguments; // should error } : () => IArguments return arguments; // should error ->arguments : any +>arguments : IArguments } function f() { @@ -169,13 +169,13 @@ function D3() { static { arguments; // should error ->arguments : any +>arguments : IArguments while(1) { >1 : 1 arguments // should error ->arguments : any +>arguments : IArguments } } } @@ -208,11 +208,11 @@ function D5() { >T : typeof T a = (() => { return arguments; })() // should error ->a : any ->(() => { return arguments; })() : any ->(() => { return arguments; }) : () => any ->() => { return arguments; } : () => any ->arguments : any +>a : IArguments +>(() => { return arguments; })() : IArguments +>(() => { return arguments; }) : () => IArguments +>() => { return arguments; } : () => IArguments +>arguments : IArguments } } @@ -224,10 +224,10 @@ function D6() { >T : typeof T a = (x = arguments) => {} // should error ->a : (x?: any) => void ->(x = arguments) => {} : (x?: any) => void ->x : any ->arguments : any +>a : (x?: IArguments) => void +>(x = arguments) => {} : (x?: IArguments) => void +>x : IArguments +>arguments : IArguments } } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff index e820f62202..9c74948e7f 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff @@ -1,65 +1,70 @@ --- old.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types +++ new.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types -@@= skipped -80, +80 lines =@@ +@@= skipped -8, +8 lines =@@ >T : typeof T - a = () => arguments // should error -->a : () => IArguments -->() => arguments : () => IArguments -->arguments : IArguments -+>a : () => any -+>() => arguments : () => any -+>arguments : any + a = arguments +->a : any +->arguments : any ++>a : IArguments ++>arguments : IArguments } } -@@= skipped -18, +18 lines =@@ - >() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void - - arguments; // should error -->arguments : IArguments -+>arguments : any - - const b = () => { -->b : () => IArguments -->() => { return arguments; // should error } : () => IArguments -+>b : () => any -+>() => { return arguments; // should error } : () => any +@@= skipped -14, +14 lines =@@ + >T : typeof T - return arguments; // should error -->arguments : IArguments -+>arguments : any - } + a = arguments +->a : any +->arguments : any ++>a : IArguments ++>arguments : IArguments + } + } - function f() { -@@= skipped -109, +109 lines =@@ +@@= skipped -13, +13 lines =@@ >T : typeof T - a = (() => { return arguments; })() // should error -->a : IArguments -->(() => { return arguments; })() : IArguments -->(() => { return arguments; }) : () => IArguments -->() => { return arguments; } : () => IArguments -->arguments : IArguments -+>a : any -+>(() => { return arguments; })() : any -+>(() => { return arguments; }) : () => any -+>() => { return arguments; } : () => any -+>arguments : any + a = { b: arguments } +->a : { b: any; } +->{ b: arguments } : { b: any; } +->b : any +->arguments : any ++>a : { b: IArguments; } ++>{ b: arguments } : { b: IArguments; } ++>b : IArguments ++>arguments : IArguments } } @@= skipped -16, +16 lines =@@ >T : typeof T - a = (x = arguments) => {} // should error -->a : (x?: IArguments) => void -->(x = arguments) => {} : (x?: IArguments) => void -->x : IArguments -->arguments : IArguments -+>a : (x?: any) => void -+>(x = arguments) => {} : (x?: any) => void -+>x : any -+>arguments : any + a = { b: arguments } +->a : { b: any; } +->{ b: arguments } : { b: any; } +->b : any +->arguments : any ++>a : { b: IArguments; } ++>{ b: arguments } : { b: IArguments; } ++>b : IArguments ++>arguments : IArguments } } + +@@= skipped -117, +117 lines =@@ + + static { + arguments; // should error +->arguments : any ++>arguments : IArguments + + while(1) { + >1 : 1 + + arguments // should error +->arguments : any ++>arguments : IArguments + } + } + } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types index 839723b765..946f253613 100644 --- a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types +++ b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types @@ -84,7 +84,7 @@ async function foo () { static { arguments; ->arguments : any +>arguments : IArguments await; >await : any @@ -113,7 +113,7 @@ function foo1 () { static { arguments; ->arguments : any +>arguments : IArguments function ff () { >ff : () => void diff --git a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff new file mode 100644 index 0000000000..895abc08e7 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff @@ -0,0 +1,20 @@ +--- old.classStaticBlock6.types ++++ new.classStaticBlock6.types +@@= skipped -83, +83 lines =@@ + + static { + arguments; +->arguments : any ++>arguments : IArguments + + await; + >await : any +@@= skipped -29, +29 lines =@@ + + static { + arguments; +->arguments : any ++>arguments : IArguments + + function ff () { + >ff : () => void \ No newline at end of file From 3c4c7818ee50e8e4aa9c8c8ef95dc0294671c41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 5 Oct 2025 23:52:30 +0200 Subject: [PATCH 3/3] Revert "check without error type" This reverts commit e2cd9c6370187b5f4db52a7cce3aaa5421ba3b65. --- internal/checker/checker.go | 1 + ...itializerOrStaticInitializationBlock.types | 60 ++++++------ ...izerOrStaticInitializationBlock.types.diff | 97 +++++++++---------- .../conformance/classStaticBlock6.types | 4 +- .../conformance/classStaticBlock6.types.diff | 20 ---- 5 files changed, 79 insertions(+), 103 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 012c6d098a..ed8b99ca7b 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -10585,6 +10585,7 @@ func (c *Checker) checkIdentifier(node *ast.Node, checkMode CheckMode) *Type { if symbol == c.argumentsSymbol { if c.isInPropertyInitializerOrClassStaticBlock(node, true /*ignoreArrowFunctions*/) { c.error(node, diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks) + return c.errorType } return c.getTypeOfSymbol(symbol) } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types index d4a10110e0..6d0798d90a 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types @@ -9,8 +9,8 @@ function A() { >T : typeof T a = arguments ->a : IArguments ->arguments : IArguments +>a : any +>arguments : any } } @@ -23,8 +23,8 @@ function A1() { >T : typeof T a = arguments ->a : IArguments ->arguments : IArguments +>a : any +>arguments : any } } @@ -36,10 +36,10 @@ function B() { >T : typeof T a = { b: arguments } ->a : { b: IArguments; } ->{ b: arguments } : { b: IArguments; } ->b : IArguments ->arguments : IArguments +>a : { b: any; } +>{ b: arguments } : { b: any; } +>b : any +>arguments : any } } @@ -52,10 +52,10 @@ function B1() { >T : typeof T a = { b: arguments } ->a : { b: IArguments; } ->{ b: arguments } : { b: IArguments; } ->b : IArguments ->arguments : IArguments +>a : { b: any; } +>{ b: arguments } : { b: any; } +>b : any +>arguments : any } } @@ -81,9 +81,9 @@ function D() { >T : typeof T a = () => arguments // should error ->a : () => IArguments ->() => arguments : () => IArguments ->arguments : IArguments +>a : () => any +>() => arguments : () => any +>arguments : any } } @@ -99,14 +99,14 @@ function D1() { >() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void arguments; // should error ->arguments : IArguments +>arguments : any const b = () => { ->b : () => IArguments ->() => { return arguments; // should error } : () => IArguments +>b : () => any +>() => { return arguments; // should error } : () => any return arguments; // should error ->arguments : IArguments +>arguments : any } function f() { @@ -169,13 +169,13 @@ function D3() { static { arguments; // should error ->arguments : IArguments +>arguments : any while(1) { >1 : 1 arguments // should error ->arguments : IArguments +>arguments : any } } } @@ -208,11 +208,11 @@ function D5() { >T : typeof T a = (() => { return arguments; })() // should error ->a : IArguments ->(() => { return arguments; })() : IArguments ->(() => { return arguments; }) : () => IArguments ->() => { return arguments; } : () => IArguments ->arguments : IArguments +>a : any +>(() => { return arguments; })() : any +>(() => { return arguments; }) : () => any +>() => { return arguments; } : () => any +>arguments : any } } @@ -224,10 +224,10 @@ function D6() { >T : typeof T a = (x = arguments) => {} // should error ->a : (x?: IArguments) => void ->(x = arguments) => {} : (x?: IArguments) => void ->x : IArguments ->arguments : IArguments +>a : (x?: any) => void +>(x = arguments) => {} : (x?: any) => void +>x : any +>arguments : any } } diff --git a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff index 9c74948e7f..e820f62202 100644 --- a/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff +++ b/testdata/baselines/reference/submodule/compiler/argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types.diff @@ -1,70 +1,65 @@ --- old.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types +++ new.argumentsUsedInClassFieldInitializerOrStaticInitializationBlock.types -@@= skipped -8, +8 lines =@@ +@@= skipped -80, +80 lines =@@ >T : typeof T - a = arguments -->a : any -->arguments : any -+>a : IArguments -+>arguments : IArguments + a = () => arguments // should error +->a : () => IArguments +->() => arguments : () => IArguments +->arguments : IArguments ++>a : () => any ++>() => arguments : () => any ++>arguments : any } } -@@= skipped -14, +14 lines =@@ - >T : typeof T +@@= skipped -18, +18 lines =@@ + >() => { arguments; // should error const b = () => { return arguments; // should error } function f() { return arguments; // ok } } : () => void - a = arguments -->a : any -->arguments : any -+>a : IArguments -+>arguments : IArguments - } - } + arguments; // should error +->arguments : IArguments ++>arguments : any + + const b = () => { +->b : () => IArguments +->() => { return arguments; // should error } : () => IArguments ++>b : () => any ++>() => { return arguments; // should error } : () => any + + return arguments; // should error +->arguments : IArguments ++>arguments : any + } -@@= skipped -13, +13 lines =@@ + function f() { +@@= skipped -109, +109 lines =@@ >T : typeof T - a = { b: arguments } -->a : { b: any; } -->{ b: arguments } : { b: any; } -->b : any -->arguments : any -+>a : { b: IArguments; } -+>{ b: arguments } : { b: IArguments; } -+>b : IArguments -+>arguments : IArguments + a = (() => { return arguments; })() // should error +->a : IArguments +->(() => { return arguments; })() : IArguments +->(() => { return arguments; }) : () => IArguments +->() => { return arguments; } : () => IArguments +->arguments : IArguments ++>a : any ++>(() => { return arguments; })() : any ++>(() => { return arguments; }) : () => any ++>() => { return arguments; } : () => any ++>arguments : any } } @@= skipped -16, +16 lines =@@ >T : typeof T - a = { b: arguments } -->a : { b: any; } -->{ b: arguments } : { b: any; } -->b : any -->arguments : any -+>a : { b: IArguments; } -+>{ b: arguments } : { b: IArguments; } -+>b : IArguments -+>arguments : IArguments + a = (x = arguments) => {} // should error +->a : (x?: IArguments) => void +->(x = arguments) => {} : (x?: IArguments) => void +->x : IArguments +->arguments : IArguments ++>a : (x?: any) => void ++>(x = arguments) => {} : (x?: any) => void ++>x : any ++>arguments : any } } - -@@= skipped -117, +117 lines =@@ - - static { - arguments; // should error -->arguments : any -+>arguments : IArguments - - while(1) { - >1 : 1 - - arguments // should error -->arguments : any -+>arguments : IArguments - } - } - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types index 946f253613..839723b765 100644 --- a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types +++ b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types @@ -84,7 +84,7 @@ async function foo () { static { arguments; ->arguments : IArguments +>arguments : any await; >await : any @@ -113,7 +113,7 @@ function foo1 () { static { arguments; ->arguments : IArguments +>arguments : any function ff () { >ff : () => void diff --git a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff b/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff deleted file mode 100644 index 895abc08e7..0000000000 --- a/testdata/baselines/reference/submodule/conformance/classStaticBlock6.types.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.classStaticBlock6.types -+++ new.classStaticBlock6.types -@@= skipped -83, +83 lines =@@ - - static { - arguments; -->arguments : any -+>arguments : IArguments - - await; - >await : any -@@= skipped -29, +29 lines =@@ - - static { - arguments; -->arguments : any -+>arguments : IArguments - - function ff () { - >ff : () => void \ No newline at end of file