diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 8aec6df21d7af..2272abb9c14df 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -12002,7 +12002,7 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup // This is true for both [[Set]] (old) and [[Define]] (ES spec) semantics. if flags&ast.ModifierFlagsStatic == 0 && core.Some(prop.Declarations, isClassInstanceProperty) { if errorNode != nil { - c.error(errorNode, diagnostics.Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super, c.symbolToString(prop)) + c.error(errorNode, diagnostics.Instance_property_0_is_defined_by_the_superclass_and_must_be_accessed_through_this_not_super, c.symbolToString(prop)) } return false } diff --git a/tsc/internal/diagnostics/diagnosticMessages.json b/tsc/internal/diagnostics/diagnosticMessages.json index 8fef6d37ff389..25a5ad4048da4 100644 --- a/tsc/internal/diagnostics/diagnosticMessages.json +++ b/tsc/internal/diagnostics/diagnosticMessages.json @@ -3930,7 +3930,7 @@ "category": "Error", "code": 2854 }, - "Class field '{0}' defined by the parent class is not accessible in the child class via super.": { + "Instance property '{0}' is defined by the superclass and must be accessed through 'this', not 'super'.": { "category": "Error", "code": 2855 }, diff --git a/tsc/internal/diagnostics/diagnostics_generated.go b/tsc/internal/diagnostics/diagnostics_generated.go index abab44d7a6fab..751f2f371e35c 100644 --- a/tsc/internal/diagnostics/diagnostics_generated.go +++ b/tsc/internal/diagnostics/diagnostics_generated.go @@ -1966,7 +1966,7 @@ var X_await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_th var Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher = &Message{code: 2854, category: CategoryError, key: "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854", text: "Top-level 'await using' statements are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'node18', 'node20', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher."} -var Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super = &Message{code: 2855, category: CategoryError, key: "Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super_2855", text: "Class field '{0}' defined by the parent class is not accessible in the child class via super."} +var Instance_property_0_is_defined_by_the_superclass_and_must_be_accessed_through_this_not_super = &Message{code: 2855, category: CategoryError, key: "Instance_property_0_is_defined_by_the_superclass_and_must_be_accessed_through_this_not_super_2855", text: "Instance property '{0}' is defined by the superclass and must be accessed through 'this', not 'super'."} var Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls = &Message{code: 2856, category: CategoryError, key: "Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls_2856", text: "Import attributes are not allowed on statements that compile to CommonJS 'require' calls."} @@ -6394,8 +6394,8 @@ func keyToMessage(key Key) *Message { return X_await_using_statements_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module case "Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_sys_2854": return Top_level_await_using_statements_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_node16_node18_node20_nodenext_or_preserve_and_the_target_option_is_set_to_es2017_or_higher - case "Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super_2855": - return Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super + case "Instance_property_0_is_defined_by_the_superclass_and_must_be_accessed_through_this_not_super_2855": + return Instance_property_0_is_defined_by_the_superclass_and_must_be_accessed_through_this_not_super case "Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls_2856": return Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls case "Import_attributes_cannot_be_used_with_type_only_imports_or_exports_2857": diff --git a/tsc/internal/diagnostics/loc/cs-CZ.json.gz b/tsc/internal/diagnostics/loc/cs-CZ.json.gz index 8dc7ed722c0e7..051fc8d972773 100644 Binary files a/tsc/internal/diagnostics/loc/cs-CZ.json.gz and b/tsc/internal/diagnostics/loc/cs-CZ.json.gz differ diff --git a/tsc/internal/diagnostics/loc/de-DE.json.gz b/tsc/internal/diagnostics/loc/de-DE.json.gz index 2b2ce37761068..effbf34949f95 100644 Binary files a/tsc/internal/diagnostics/loc/de-DE.json.gz and b/tsc/internal/diagnostics/loc/de-DE.json.gz differ diff --git a/tsc/internal/diagnostics/loc/es-ES.json.gz b/tsc/internal/diagnostics/loc/es-ES.json.gz index ea7b2fe4852c4..97ab5d63f43e5 100644 Binary files a/tsc/internal/diagnostics/loc/es-ES.json.gz and b/tsc/internal/diagnostics/loc/es-ES.json.gz differ diff --git a/tsc/internal/diagnostics/loc/fr-FR.json.gz b/tsc/internal/diagnostics/loc/fr-FR.json.gz index bb643415f0060..0e754d26d67bf 100644 Binary files a/tsc/internal/diagnostics/loc/fr-FR.json.gz and b/tsc/internal/diagnostics/loc/fr-FR.json.gz differ diff --git a/tsc/internal/diagnostics/loc/it-IT.json.gz b/tsc/internal/diagnostics/loc/it-IT.json.gz index df33a1298ed1c..ef3d16ee74003 100644 Binary files a/tsc/internal/diagnostics/loc/it-IT.json.gz and b/tsc/internal/diagnostics/loc/it-IT.json.gz differ diff --git a/tsc/internal/diagnostics/loc/ja-JP.json.gz b/tsc/internal/diagnostics/loc/ja-JP.json.gz index c0b74b6e08943..97c02edb422dc 100644 Binary files a/tsc/internal/diagnostics/loc/ja-JP.json.gz and b/tsc/internal/diagnostics/loc/ja-JP.json.gz differ diff --git a/tsc/internal/diagnostics/loc/ko-KR.json.gz b/tsc/internal/diagnostics/loc/ko-KR.json.gz index 05533911776d4..b1159830fc97f 100644 Binary files a/tsc/internal/diagnostics/loc/ko-KR.json.gz and b/tsc/internal/diagnostics/loc/ko-KR.json.gz differ diff --git a/tsc/internal/diagnostics/loc/pl-PL.json.gz b/tsc/internal/diagnostics/loc/pl-PL.json.gz index 52354c8c87ebc..ae25c2dc34d15 100644 Binary files a/tsc/internal/diagnostics/loc/pl-PL.json.gz and b/tsc/internal/diagnostics/loc/pl-PL.json.gz differ diff --git a/tsc/internal/diagnostics/loc/pt-BR.json.gz b/tsc/internal/diagnostics/loc/pt-BR.json.gz index 35093d14d301f..d5bff7aee3c30 100644 Binary files a/tsc/internal/diagnostics/loc/pt-BR.json.gz and b/tsc/internal/diagnostics/loc/pt-BR.json.gz differ diff --git a/tsc/internal/diagnostics/loc/ru-RU.json.gz b/tsc/internal/diagnostics/loc/ru-RU.json.gz index 4556ffc2fa643..dd45e38856cce 100644 Binary files a/tsc/internal/diagnostics/loc/ru-RU.json.gz and b/tsc/internal/diagnostics/loc/ru-RU.json.gz differ diff --git a/tsc/internal/diagnostics/loc/tr-TR.json.gz b/tsc/internal/diagnostics/loc/tr-TR.json.gz index 7ce421335fceb..59a52c94050a0 100644 Binary files a/tsc/internal/diagnostics/loc/tr-TR.json.gz and b/tsc/internal/diagnostics/loc/tr-TR.json.gz differ diff --git a/tsc/internal/diagnostics/loc/zh-CN.json.gz b/tsc/internal/diagnostics/loc/zh-CN.json.gz index 2f22028d4fe67..e6a33e29a009e 100644 Binary files a/tsc/internal/diagnostics/loc/zh-CN.json.gz and b/tsc/internal/diagnostics/loc/zh-CN.json.gz differ diff --git a/tsc/internal/diagnostics/loc/zh-TW.json.gz b/tsc/internal/diagnostics/loc/zh-TW.json.gz index b6900d72972e5..394f4b7b635e3 100644 Binary files a/tsc/internal/diagnostics/loc/zh-TW.json.gz and b/tsc/internal/diagnostics/loc/zh-TW.json.gz differ diff --git a/tsc/testdata/baselines/reference/compiler/checkSuperCallBeforeThisAccess.errors.txt b/tsc/testdata/baselines/reference/compiler/checkSuperCallBeforeThisAccess.errors.txt index 78a512d71317e..c5e5470f69a61 100644 --- a/tsc/testdata/baselines/reference/compiler/checkSuperCallBeforeThisAccess.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/checkSuperCallBeforeThisAccess.errors.txt @@ -1,19 +1,19 @@ checkSuperCallBeforeThisAccess.ts(7,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(8,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(9,18): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. -checkSuperCallBeforeThisAccess.ts(9,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. -checkSuperCallBeforeThisAccess.ts(12,30): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. -checkSuperCallBeforeThisAccess.ts(17,28): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +checkSuperCallBeforeThisAccess.ts(9,24): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. +checkSuperCallBeforeThisAccess.ts(12,30): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. +checkSuperCallBeforeThisAccess.ts(17,28): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. checkSuperCallBeforeThisAccess.ts(20,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(21,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(22,22): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. -checkSuperCallBeforeThisAccess.ts(22,28): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +checkSuperCallBeforeThisAccess.ts(22,28): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. checkSuperCallBeforeThisAccess.ts(30,30): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(39,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(43,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(44,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(45,18): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. -checkSuperCallBeforeThisAccess.ts(45,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +checkSuperCallBeforeThisAccess.ts(45,24): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. checkSuperCallBeforeThisAccess.ts(59,27): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. checkSuperCallBeforeThisAccess.ts(75,27): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. @@ -35,19 +35,19 @@ checkSuperCallBeforeThisAccess.ts(75,27): error TS17009: 'super' must be called ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. let a4 = () => this; let a5 = () => this.x; let a6 = () => super.x; ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. if (!!true) { super(); let b1 = this; let b2 = this.x; let b3 = super.x; ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. } else { let c1 = this; // Error @@ -60,7 +60,7 @@ checkSuperCallBeforeThisAccess.ts(75,27): error TS17009: 'super' must be called ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. } if (!!true) { switch (n) { @@ -95,7 +95,7 @@ checkSuperCallBeforeThisAccess.ts(75,27): error TS17009: 'super' must be called ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. } } diff --git a/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessible.errors.txt b/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessible.errors.txt index 6e8cdf21e69a3..fa68f02e17a1b 100644 --- a/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessible.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessible.errors.txt @@ -1,4 +1,4 @@ -classFieldSuperNotAccessible.ts(6,15): error TS2855: Class field 'field' defined by the parent class is not accessible in the child class via super. +classFieldSuperNotAccessible.ts(6,15): error TS2855: Instance property 'field' is defined by the superclass and must be accessed through 'this', not 'super'. ==== classFieldSuperNotAccessible.ts (1 errors) ==== @@ -9,7 +9,7 @@ classFieldSuperNotAccessible.ts(6,15): error TS2855: Class field 'field' defined f() { super.field() // error ~~~~~ -!!! error TS2855: Class field 'field' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'field' is defined by the superclass and must be accessed through 'this', not 'super'. } } diff --git a/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessibleJs.errors.txt b/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessibleJs.errors.txt index 4e0b0fcf1b530..5fea2149c2ed3 100644 --- a/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessibleJs.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/classFieldSuperNotAccessibleJs.errors.txt @@ -1,8 +1,8 @@ index.js(7,14): error TS2339: Property 'justProp' does not exist on type 'YaddaBase'. index.js(9,9): error TS7053: Element implicitly has an 'any' type because expression of type '"literalElementAccess"' can't be used to index type 'YaddaBase'. Property 'literalElementAccess' does not exist on type 'YaddaBase'. -index.js(20,22): error TS2855: Class field 'roots' defined by the parent class is not accessible in the child class via super. -index.js(23,22): error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. +index.js(20,22): error TS2855: Instance property 'roots' is defined by the superclass and must be accessed through 'this', not 'super'. +index.js(23,22): error TS2855: Instance property 'foo' is defined by the superclass and must be accessed through 'this', not 'super'. index.js(26,22): error TS2339: Property 'justProp' does not exist on type 'YaddaBase'. index.js(29,22): error TS2339: Property 'literalElementAccess' does not exist on type 'YaddaBase'. @@ -34,12 +34,12 @@ index.js(29,22): error TS2339: Property 'literalElementAccess' does not exist on get rootTests() { return super.roots; ~~~~~ -!!! error TS2855: Class field 'roots' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'roots' is defined by the superclass and must be accessed through 'this', not 'super'. } get fooTests() { return super.foo; ~~~ -!!! error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'foo' is defined by the superclass and must be accessed through 'this', not 'super'. } get justPropTests() { return super.justProp; diff --git a/tsc/testdata/baselines/reference/compiler/superAccess(target=es2015).errors.txt b/tsc/testdata/baselines/reference/compiler/superAccess(target=es2015).errors.txt index f8fb17f9ee148..99a8a9160bce6 100644 --- a/tsc/testdata/baselines/reference/compiler/superAccess(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/superAccess(target=es2015).errors.txt @@ -1,6 +1,6 @@ superAccess.ts(9,24): error TS2576: Property 'S1' does not exist on type 'MyBase'. Did you mean to access the static member 'MyBase.S1' instead? -superAccess.ts(10,24): error TS2855: Class field 'S2' defined by the parent class is not accessible in the child class via super. -superAccess.ts(11,24): error TS2855: Class field 'f' defined by the parent class is not accessible in the child class via super. +superAccess.ts(10,24): error TS2855: Instance property 'S2' is defined by the superclass and must be accessed through 'this', not 'super'. +superAccess.ts(11,24): error TS2855: Instance property 'f' is defined by the superclass and must be accessed through 'this', not 'super'. ==== superAccess.ts (3 errors) ==== @@ -17,9 +17,9 @@ superAccess.ts(11,24): error TS2855: Class field 'f' defined by the parent class !!! error TS2576: Property 'S1' does not exist on type 'MyBase'. Did you mean to access the static member 'MyBase.S1' instead? var l4 = super.S2; // Expected => Error: Only public instance methods of the base class are accessible via the 'super' keyword ~~ -!!! error TS2855: Class field 'S2' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'S2' is defined by the superclass and must be accessed through 'this', not 'super'. var l5 = super.f(); // Expected => Error: Only public instance methods of the base class are accessible via the 'super' keyword ~ -!!! error TS2855: Class field 'f' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'f' is defined by the superclass and must be accessed through 'this', not 'super'. } } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.errors.txt b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.errors.txt new file mode 100644 index 0000000000000..7021021896e64 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.errors.txt @@ -0,0 +1,18 @@ +superAccessProtectedInstanceProperty.ts(9,22): error TS2855: Instance property 'roots' is defined by the superclass and must be accessed through 'this', not 'super'. + + +==== superAccessProtectedInstanceProperty.ts (1 errors) ==== + // https://github.com/microsoft/TypeScript/issues/55883 + + export abstract class YaddaBase { + protected roots = "hi"; + } + + export class DerivedYadda extends YaddaBase { + public get rootTests() { + return super.roots; + ~~~~~ +!!! error TS2855: Instance property 'roots' is defined by the superclass and must be accessed through 'this', not 'super'. + } + } + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.js b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.js new file mode 100644 index 0000000000000..1ebbd2b08e7dc --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/superAccessProtectedInstanceProperty.ts] //// + +//// [superAccessProtectedInstanceProperty.ts] +// https://github.com/microsoft/TypeScript/issues/55883 + +export abstract class YaddaBase { + protected roots = "hi"; +} + +export class DerivedYadda extends YaddaBase { + public get rootTests() { + return super.roots; + } +} + + +//// [superAccessProtectedInstanceProperty.js] +// https://github.com/microsoft/TypeScript/issues/55883 +export class YaddaBase { + roots = "hi"; +} +export class DerivedYadda extends YaddaBase { + get rootTests() { + return super.roots; + } +} diff --git a/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.symbols b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.symbols new file mode 100644 index 0000000000000..d33041012a1c9 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.symbols @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/superAccessProtectedInstanceProperty.ts] //// + +=== superAccessProtectedInstanceProperty.ts === +// https://github.com/microsoft/TypeScript/issues/55883 + +export abstract class YaddaBase { +>YaddaBase : Symbol(YaddaBase, Decl(superAccessProtectedInstanceProperty.ts, 0, 0)) + + protected roots = "hi"; +>roots : Symbol(YaddaBase.roots, Decl(superAccessProtectedInstanceProperty.ts, 2, 33)) +} + +export class DerivedYadda extends YaddaBase { +>DerivedYadda : Symbol(DerivedYadda, Decl(superAccessProtectedInstanceProperty.ts, 4, 1)) +>YaddaBase : Symbol(YaddaBase, Decl(superAccessProtectedInstanceProperty.ts, 0, 0)) + + public get rootTests() { +>rootTests : Symbol(DerivedYadda.rootTests, Decl(superAccessProtectedInstanceProperty.ts, 6, 45)) + + return super.roots; +>super.roots : Symbol(YaddaBase.roots, Decl(superAccessProtectedInstanceProperty.ts, 2, 33)) +>super : Symbol(YaddaBase, Decl(superAccessProtectedInstanceProperty.ts, 0, 0)) +>roots : Symbol(YaddaBase.roots, Decl(superAccessProtectedInstanceProperty.ts, 2, 33)) + } +} + diff --git a/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.types b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.types new file mode 100644 index 0000000000000..7d41366341bd2 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/superAccessProtectedInstanceProperty.types @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/superAccessProtectedInstanceProperty.ts] //// + +=== superAccessProtectedInstanceProperty.ts === +// https://github.com/microsoft/TypeScript/issues/55883 + +export abstract class YaddaBase { +>YaddaBase : YaddaBase + + protected roots = "hi"; +>roots : string +>"hi" : "hi" +} + +export class DerivedYadda extends YaddaBase { +>DerivedYadda : DerivedYadda +>YaddaBase : YaddaBase + + public get rootTests() { +>rootTests : string + + return super.roots; +>super.roots : string +>super : YaddaBase +>roots : string + } +} + diff --git a/tsc/testdata/baselines/reference/compiler/superInLambdas(target=es2015).errors.txt b/tsc/testdata/baselines/reference/compiler/superInLambdas(target=es2015).errors.txt index 4d46f490044e5..1cc55fb81eeee 100644 --- a/tsc/testdata/baselines/reference/compiler/superInLambdas(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/superInLambdas(target=es2015).errors.txt @@ -1,5 +1,5 @@ -superInLambdas.ts(47,49): error TS2855: Class field 'name' defined by the parent class is not accessible in the child class via super. -superInLambdas.ts(51,49): error TS2855: Class field 'name' defined by the parent class is not accessible in the child class via super. +superInLambdas.ts(47,49): error TS2855: Instance property 'name' is defined by the superclass and must be accessed through 'this', not 'super'. +superInLambdas.ts(51,49): error TS2855: Instance property 'name' is defined by the superclass and must be accessed through 'this', not 'super'. superInLambdas.ts(61,34): error TS1034: 'super' must be followed by an argument list or member access. superInLambdas.ts(65,34): error TS1034: 'super' must be followed by an argument list or member access. @@ -53,13 +53,13 @@ superInLambdas.ts(65,34): error TS1034: 'super' must be followed by an argument // super property in a nested lambda in a constructor var superName = () => () => () => super.name; ~~~~ -!!! error TS2855: Class field 'name' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'name' is defined by the superclass and must be accessed through 'this', not 'super'. } sayHello(): void { // super property in a nested lambda in a method var superName = () => () => () => super.name; ~~~~ -!!! error TS2855: Class field 'name' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'name' is defined by the superclass and must be accessed through 'this', not 'super'. } } diff --git a/tsc/testdata/baselines/reference/compiler/superPropertyAccess(target=es2015).errors.txt b/tsc/testdata/baselines/reference/compiler/superPropertyAccess(target=es2015).errors.txt index 108616c2ac4c5..d21e5d71bf76c 100644 --- a/tsc/testdata/baselines/reference/compiler/superPropertyAccess(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/compiler/superPropertyAccess(target=es2015).errors.txt @@ -1,7 +1,7 @@ -superPropertyAccess.ts(21,15): error TS2855: Class field 'm2' defined by the parent class is not accessible in the child class via super. +superPropertyAccess.ts(21,15): error TS2855: Instance property 'm2' is defined by the superclass and must be accessed through 'this', not 'super'. superPropertyAccess.ts(23,15): error TS2341: Property 'p1' is private and only accessible within class 'MyBase'. -superPropertyAccess.ts(25,24): error TS2855: Class field 'd1' defined by the parent class is not accessible in the child class via super. -superPropertyAccess.ts(27,24): error TS2855: Class field 'd2' defined by the parent class is not accessible in the child class via super. +superPropertyAccess.ts(25,24): error TS2855: Instance property 'd1' is defined by the superclass and must be accessed through 'this', not 'super'. +superPropertyAccess.ts(27,24): error TS2855: Instance property 'd2' is defined by the superclass and must be accessed through 'this', not 'super'. ==== superPropertyAccess.ts (4 errors) ==== @@ -27,7 +27,7 @@ superPropertyAccess.ts(27,24): error TS2855: Class field 'd2' defined by the par super.m2.bind(this); // Should error, instance property, not a public instance member function ~~ -!!! error TS2855: Class field 'm2' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'm2' is defined by the superclass and must be accessed through 'this', not 'super'. super.p1(); // Should error, private not public instance member function ~~ @@ -35,11 +35,11 @@ superPropertyAccess.ts(27,24): error TS2855: Class field 'd2' defined by the par var l1 = super.d1; // Should error, instance data property not a public instance member function ~~ -!!! error TS2855: Class field 'd1' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'd1' is defined by the superclass and must be accessed through 'this', not 'super'. var l1 = super.d2; // Should error, instance data property not a public instance member function ~~ -!!! error TS2855: Class field 'd2' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'd2' is defined by the superclass and must be accessed through 'this', not 'super'. super.m1 = function (a: string) { return ""; }; // Should be allowed, we will not restrict assignment diff --git a/tsc/testdata/baselines/reference/conformance/errorSuperPropertyAccess(target=es2015).errors.txt b/tsc/testdata/baselines/reference/conformance/errorSuperPropertyAccess(target=es2015).errors.txt index f0a5fe433238e..b3b29fc0212e5 100644 --- a/tsc/testdata/baselines/reference/conformance/errorSuperPropertyAccess(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/conformance/errorSuperPropertyAccess(target=es2015).errors.txt @@ -7,16 +7,16 @@ errorSuperPropertyAccess.ts(16,9): error TS2335: 'super' can only be referenced errorSuperPropertyAccess.ts(21,9): error TS2335: 'super' can only be referenced in a derived class. errorSuperPropertyAccess.ts(25,9): error TS2335: 'super' can only be referenced in a derived class. errorSuperPropertyAccess.ts(30,9): error TS2335: 'super' can only be referenced in a derived class. -errorSuperPropertyAccess.ts(57,15): error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. -errorSuperPropertyAccess.ts(61,23): error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. -errorSuperPropertyAccess.ts(65,23): error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. -errorSuperPropertyAccess.ts(69,19): error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. +errorSuperPropertyAccess.ts(57,15): error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. +errorSuperPropertyAccess.ts(61,23): error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. +errorSuperPropertyAccess.ts(65,23): error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. +errorSuperPropertyAccess.ts(69,19): error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. errorSuperPropertyAccess.ts(73,13): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. errorSuperPropertyAccess.ts(76,40): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. -errorSuperPropertyAccess.ts(87,15): error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. -errorSuperPropertyAccess.ts(91,23): error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. -errorSuperPropertyAccess.ts(95,23): error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. -errorSuperPropertyAccess.ts(99,19): error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. +errorSuperPropertyAccess.ts(87,15): error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. +errorSuperPropertyAccess.ts(91,23): error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. +errorSuperPropertyAccess.ts(95,23): error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. +errorSuperPropertyAccess.ts(99,19): error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. errorSuperPropertyAccess.ts(110,15): error TS2341: Property 'privateStaticMember' is private and only accessible within class 'SomeBase'. errorSuperPropertyAccess.ts(111,15): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. errorSuperPropertyAccess.ts(115,15): error TS2341: Property 'privateStaticMember' is private and only accessible within class 'SomeBase'. @@ -104,25 +104,25 @@ errorSuperPropertyAccess.ts(127,30): error TS2660: 'super' can only be reference super(); super.publicMember = 1; ~~~~~~~~~~~~ -!!! error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. } fn() { var x = super.publicMember; ~~~~~~~~~~~~ -!!! error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. } get a() { var x = super.publicMember; ~~~~~~~~~~~~ -!!! error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. return undefined; } set a(n) { n = super.publicMember; ~~~~~~~~~~~~ -!!! error TS2855: Class field 'publicMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'publicMember' is defined by the superclass and must be accessed through 'this', not 'super'. } fn2() { function inner() { @@ -146,25 +146,25 @@ errorSuperPropertyAccess.ts(127,30): error TS2660: 'super' can only be reference super(); super.privateMember = 1; ~~~~~~~~~~~~~ -!!! error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. } fn() { var x = super.privateMember; ~~~~~~~~~~~~~ -!!! error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. } get a() { var x = super.privateMember; ~~~~~~~~~~~~~ -!!! error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. return undefined; } set a(n) { n = super.privateMember; ~~~~~~~~~~~~~ -!!! error TS2855: Class field 'privateMember' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'privateMember' is defined by the superclass and must be accessed through 'this', not 'super'. } } diff --git a/tsc/testdata/baselines/reference/conformance/parserAstSpans1(target=es2015).errors.txt b/tsc/testdata/baselines/reference/conformance/parserAstSpans1(target=es2015).errors.txt index d7734fe98e67e..07724286ace8d 100644 --- a/tsc/testdata/baselines/reference/conformance/parserAstSpans1(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/conformance/parserAstSpans1(target=es2015).errors.txt @@ -6,7 +6,7 @@ parserAstSpans1.ts(48,1): error TS2454: Variable 'i1_i' is used before being ass parserAstSpans1.ts(49,1): error TS2454: Variable 'i1_i' is used before being assigned. parserAstSpans1.ts(50,1): error TS2454: Variable 'i1_i' is used before being assigned. parserAstSpans1.ts(51,1): error TS2454: Variable 'i1_i' is used before being assigned. -parserAstSpans1.ts(111,25): error TS2855: Class field 'c2_p1' defined by the parent class is not accessible in the child class via super. +parserAstSpans1.ts(111,25): error TS2855: Instance property 'c2_p1' is defined by the superclass and must be accessed through 'this', not 'super'. parserAstSpans1.ts(182,1): error TS2454: Variable 'i2_i' is used before being assigned. parserAstSpans1.ts(183,1): error TS2454: Variable 'i2_i' is used before being assigned. parserAstSpans1.ts(184,1): error TS2454: Variable 'i2_i' is used before being assigned. @@ -24,7 +24,7 @@ parserAstSpans1.ts(195,1): error TS2454: Variable 'i3_i' is used before being as parserAstSpans1.ts(196,1): error TS2454: Variable 'i3_i' is used before being assigned. parserAstSpans1.ts(197,1): error TS2454: Variable 'i3_i' is used before being assigned. parserAstSpans1.ts(199,8): error TS2454: Variable 'i3_i' is used before being assigned. -parserAstSpans1.ts(217,24): error TS2855: Class field 'b' defined by the parent class is not accessible in the child class via super. +parserAstSpans1.ts(217,24): error TS2855: Instance property 'b' is defined by the superclass and must be accessed through 'this', not 'super'. ==== parserAstSpans1.ts (27 errors) ==== @@ -156,7 +156,7 @@ parserAstSpans1.ts(217,24): error TS2855: Class field 'b' defined by the parent super(10); this.p1 = super.c2_p1; ~~~~~ -!!! error TS2855: Class field 'c2_p1' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'c2_p1' is defined by the superclass and must be accessed through 'this', not 'super'. } /** c3 p1*/ public p1!: number; @@ -298,6 +298,6 @@ parserAstSpans1.ts(217,24): error TS2855: Class field 'b' defined by the parent super(); this.d = super.b; ~ -!!! error TS2855: Class field 'b' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'b' is defined by the superclass and must be accessed through 'this', not 'super'. } } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/privateInstanceMemberAccessibility(target=es2015).errors.txt b/tsc/testdata/baselines/reference/conformance/privateInstanceMemberAccessibility(target=es2015).errors.txt index ef5eaed6c511d..b93710c2ee8aa 100644 --- a/tsc/testdata/baselines/reference/conformance/privateInstanceMemberAccessibility(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/conformance/privateInstanceMemberAccessibility(target=es2015).errors.txt @@ -1,7 +1,7 @@ privateInstanceMemberAccessibility.ts(5,7): error TS2415: Class 'Derived' incorrectly extends base class 'Base'. Property 'foo' is private in type 'Base' but not in type 'Derived'. -privateInstanceMemberAccessibility.ts(6,15): error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. -privateInstanceMemberAccessibility.ts(8,22): error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. +privateInstanceMemberAccessibility.ts(6,15): error TS2855: Instance property 'foo' is defined by the superclass and must be accessed through 'this', not 'super'. +privateInstanceMemberAccessibility.ts(8,22): error TS2855: Instance property 'foo' is defined by the superclass and must be accessed through 'this', not 'super'. privateInstanceMemberAccessibility.ts(10,15): error TS2304: Cannot find name 'super'. privateInstanceMemberAccessibility.ts(12,12): error TS1442: Expected '=' for property initializer. @@ -17,11 +17,11 @@ privateInstanceMemberAccessibility.ts(12,12): error TS1442: Expected '=' for pro !!! error TS2415: Property 'foo' is private in type 'Base' but not in type 'Derived'. x = super.foo; // error ~~~ -!!! error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'foo' is defined by the superclass and must be accessed through 'this', not 'super'. y() { return super.foo; // error ~~~ -!!! error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'foo' is defined by the superclass and must be accessed through 'this', not 'super'. } z: typeof super.foo; // error ~~~~~ diff --git a/tsc/testdata/baselines/reference/conformance/protectedClassPropertyAccessibleWithinSubclass3(target=es2015).errors.txt b/tsc/testdata/baselines/reference/conformance/protectedClassPropertyAccessibleWithinSubclass3(target=es2015).errors.txt index 816af598605f5..544950d94394c 100644 --- a/tsc/testdata/baselines/reference/conformance/protectedClassPropertyAccessibleWithinSubclass3(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/conformance/protectedClassPropertyAccessibleWithinSubclass3(target=es2015).errors.txt @@ -1,5 +1,5 @@ protectedClassPropertyAccessibleWithinSubclass3.ts(2,15): error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor. -protectedClassPropertyAccessibleWithinSubclass3.ts(11,15): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +protectedClassPropertyAccessibleWithinSubclass3.ts(11,15): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. ==== protectedClassPropertyAccessibleWithinSubclass3.ts (2 errors) ==== @@ -17,6 +17,6 @@ protectedClassPropertyAccessibleWithinSubclass3.ts(11,15): error TS2855: Class f this.x; // OK, accessed within a subclass of the declaring class super.x; // Error, x is not public ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. } } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/protectedInstanceMemberAccessibility(target=es2015).errors.txt b/tsc/testdata/baselines/reference/conformance/protectedInstanceMemberAccessibility(target=es2015).errors.txt index 42ba84a412d0e..f082ef59c830f 100644 --- a/tsc/testdata/baselines/reference/conformance/protectedInstanceMemberAccessibility(target=es2015).errors.txt +++ b/tsc/testdata/baselines/reference/conformance/protectedInstanceMemberAccessibility(target=es2015).errors.txt @@ -1,5 +1,5 @@ protectedInstanceMemberAccessibility.ts(14,23): error TS2339: Property 'z' does not exist on type 'B'. -protectedInstanceMemberAccessibility.ts(16,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +protectedInstanceMemberAccessibility.ts(16,24): error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. protectedInstanceMemberAccessibility.ts(18,24): error TS2339: Property 'y' does not exist on type 'A'. protectedInstanceMemberAccessibility.ts(19,24): error TS2339: Property 'z' does not exist on type 'A'. protectedInstanceMemberAccessibility.ts(22,20): error TS2446: Property 'x' is protected and only accessible through an instance of class 'B'. This is an instance of class 'A'. @@ -33,7 +33,7 @@ protectedInstanceMemberAccessibility.ts(37,20): error TS2445: Property 'z' is pr var s1 = super.x; // error ~ -!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super. +!!! error TS2855: Instance property 'x' is defined by the superclass and must be accessed through 'this', not 'super'. var s2 = super.f(); var s3 = super.y; // error ~ diff --git a/tsc/testdata/tests/cases/compiler/superAccessProtectedInstanceProperty.ts b/tsc/testdata/tests/cases/compiler/superAccessProtectedInstanceProperty.ts new file mode 100644 index 0000000000000..b16e629623114 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/superAccessProtectedInstanceProperty.ts @@ -0,0 +1,11 @@ +// https://github.com/microsoft/TypeScript/issues/55883 + +export abstract class YaddaBase { + protected roots = "hi"; +} + +export class DerivedYadda extends YaddaBase { + public get rootTests() { + return super.roots; + } +}