From 51caec23508c9be7d2efaa4cd1e681960f2ad763 Mon Sep 17 00:00:00 2001 From: bashdx Date: Tue, 3 Jul 2018 21:03:13 +0200 Subject: [PATCH 1/5] Implementation for issue #25002 --- lib/enu/diagnosticMessages.generated.json.lcg | 2 +- lib/tsc.js | 3 ++- src/compiler/checker.ts | 11 +++++++++-- src/compiler/diagnosticMessages.json | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/enu/diagnosticMessages.generated.json.lcg b/lib/enu/diagnosticMessages.generated.json.lcg index 7199fab2a5237..0233619d876d6 100644 --- a/lib/enu/diagnosticMessages.generated.json.lcg +++ b/lib/enu/diagnosticMessages.generated.json.lcg @@ -6323,7 +6323,7 @@ - + diff --git a/lib/tsc.js b/lib/tsc.js index c4211aa1b3b45..faebc296a96c3 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -2942,7 +2942,7 @@ var ts; Constructors_for_derived_classes_must_contain_a_super_call: diag(2377, ts.DiagnosticCategory.Error, "Constructors_for_derived_classes_must_contain_a_super_call_2377", "Constructors for derived classes must contain a 'super' call."), A_get_accessor_must_return_a_value: diag(2378, ts.DiagnosticCategory.Error, "A_get_accessor_must_return_a_value_2378", "A 'get' accessor must return a value."), Getter_and_setter_accessors_do_not_agree_in_visibility: diag(2379, ts.DiagnosticCategory.Error, "Getter_and_setter_accessors_do_not_agree_in_visibility_2379", "Getter and setter accessors do not agree in visibility."), - get_and_set_accessor_must_have_the_same_type: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type."), + get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'."), A_signature_with_an_implementation_cannot_use_a_string_literal_type: diag(2381, ts.DiagnosticCategory.Error, "A_signature_with_an_implementation_cannot_use_a_string_literal_type_2381", "A signature with an implementation cannot use a string literal type."), Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: diag(2382, ts.DiagnosticCategory.Error, "Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature_2382", "Specialized overload signature is not assignable to any non-specialized signature."), Overload_signatures_must_all_be_exported_or_non_exported: diag(2383, ts.DiagnosticCategory.Error, "Overload_signatures_must_all_be_exported_or_non_exported_2383", "Overload signatures must all be exported or non-exported."), @@ -3212,6 +3212,7 @@ var ts; Class_name_cannot_be_Object_when_targeting_ES5_with_module_0: diag(2725, ts.DiagnosticCategory.Error, "Class_name_cannot_be_Object_when_targeting_ES5_with_module_0_2725", "Class name cannot be 'Object' when targeting ES5 with module {0}."), Cannot_find_lib_definition_for_0: diag(2726, ts.DiagnosticCategory.Error, "Cannot_find_lib_definition_for_0_2726", "Cannot find lib definition for '{0}'."), Cannot_find_lib_definition_for_0_Did_you_mean_1: diag(2727, ts.DiagnosticCategory.Error, "Cannot_find_lib_definition_for_0_Did_you_mean_1_2727", "Cannot find lib definition for '{0}'. Did you mean '{1}'?"), + The_respective_set_accessor_has_the_type_0: diag(2730, ts.DiagnosticCategory.Error, "The_respective_set_accessor_has_the_type_0_2730", "The respective 'set' accessor has the type '{0}'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ef78683171036..4d713dff28254 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21801,7 +21801,7 @@ namespace ts { // TypeScript 1.0 spec (April 2014): 4.5 // If both accessors include type annotations, the specified types must be identical. - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1); checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } @@ -21817,7 +21817,14 @@ namespace ts { const firstType = getAnnotatedType(first); const secondType = getAnnotatedType(second); if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) { - error(first, message); + + if(isGetAccessor(first)){ + const typeNameFirstType = typeToString(firstType); + const typeNameSecondType = typeToString(secondType); + + const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType); + diagnostic.relatedInformation = [createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)]; + } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a9ba19d91d408..d693d38c41df8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1304,7 +1304,7 @@ "category": "Error", "code": 2379 }, - "'get' and 'set' accessor must have the same type.": { + "'get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'.": { "category": "Error", "code": 2380 }, @@ -2397,6 +2397,10 @@ "category": "Error", "code": 2727 }, + "The respective 'set' accessor has the type '{0}'.": { + "category": "Error", + "code": 2730 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From 2f0cc5360a60284a7542ff670d4420cc9949ec55 Mon Sep 17 00:00:00 2001 From: bashdx Date: Tue, 3 Jul 2018 21:10:58 +0200 Subject: [PATCH 2/5] Implementation for issue #25002 --- lib/enu/diagnosticMessages.generated.json.lcg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enu/diagnosticMessages.generated.json.lcg b/lib/enu/diagnosticMessages.generated.json.lcg index 0233619d876d6..a0eec07b5b797 100644 --- a/lib/enu/diagnosticMessages.generated.json.lcg +++ b/lib/enu/diagnosticMessages.generated.json.lcg @@ -6323,7 +6323,7 @@ - + From bf1af7ac7601213c3706aab73e2ef62fa5c0860c Mon Sep 17 00:00:00 2001 From: bashdx Date: Wed, 4 Jul 2018 21:04:39 +0200 Subject: [PATCH 3/5] #25002 - changed error message --- lib/enu/diagnosticMessages.generated.json.lcg | 2 +- lib/tsc.js | 3 +-- src/compiler/checker.ts | 11 ++++------ src/compiler/diagnosticMessages.json | 2 +- .../abstractPropertyNegative.errors.txt | 10 ++++++---- .../reference/api/tsserverlibrary.d.ts | 3 ++- .../getAndSetNotIdenticalType.errors.txt | 10 ++++++---- .../getAndSetNotIdenticalType2.errors.txt | 10 ++++++---- .../getAndSetNotIdenticalType3.errors.txt | 10 ++++++---- .../reference/objectLiteralErrors.errors.txt | 20 +++++++++++-------- .../thisTypeInAccessorsNegative.errors.txt | 2 ++ 11 files changed, 47 insertions(+), 36 deletions(-) diff --git a/lib/enu/diagnosticMessages.generated.json.lcg b/lib/enu/diagnosticMessages.generated.json.lcg index a0eec07b5b797..7199fab2a5237 100644 --- a/lib/enu/diagnosticMessages.generated.json.lcg +++ b/lib/enu/diagnosticMessages.generated.json.lcg @@ -6323,7 +6323,7 @@ - + diff --git a/lib/tsc.js b/lib/tsc.js index faebc296a96c3..c4211aa1b3b45 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -2942,7 +2942,7 @@ var ts; Constructors_for_derived_classes_must_contain_a_super_call: diag(2377, ts.DiagnosticCategory.Error, "Constructors_for_derived_classes_must_contain_a_super_call_2377", "Constructors for derived classes must contain a 'super' call."), A_get_accessor_must_return_a_value: diag(2378, ts.DiagnosticCategory.Error, "A_get_accessor_must_return_a_value_2378", "A 'get' accessor must return a value."), Getter_and_setter_accessors_do_not_agree_in_visibility: diag(2379, ts.DiagnosticCategory.Error, "Getter_and_setter_accessors_do_not_agree_in_visibility_2379", "Getter and setter accessors do not agree in visibility."), - get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'."), + get_and_set_accessor_must_have_the_same_type: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type."), A_signature_with_an_implementation_cannot_use_a_string_literal_type: diag(2381, ts.DiagnosticCategory.Error, "A_signature_with_an_implementation_cannot_use_a_string_literal_type_2381", "A signature with an implementation cannot use a string literal type."), Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: diag(2382, ts.DiagnosticCategory.Error, "Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature_2382", "Specialized overload signature is not assignable to any non-specialized signature."), Overload_signatures_must_all_be_exported_or_non_exported: diag(2383, ts.DiagnosticCategory.Error, "Overload_signatures_must_all_be_exported_or_non_exported_2383", "Overload signatures must all be exported or non-exported."), @@ -3212,7 +3212,6 @@ var ts; Class_name_cannot_be_Object_when_targeting_ES5_with_module_0: diag(2725, ts.DiagnosticCategory.Error, "Class_name_cannot_be_Object_when_targeting_ES5_with_module_0_2725", "Class name cannot be 'Object' when targeting ES5 with module {0}."), Cannot_find_lib_definition_for_0: diag(2726, ts.DiagnosticCategory.Error, "Cannot_find_lib_definition_for_0_2726", "Cannot find lib definition for '{0}'."), Cannot_find_lib_definition_for_0_Did_you_mean_1: diag(2727, ts.DiagnosticCategory.Error, "Cannot_find_lib_definition_for_0_Did_you_mean_1_2727", "Cannot find lib definition for '{0}'. Did you mean '{1}'?"), - The_respective_set_accessor_has_the_type_0: diag(2730, ts.DiagnosticCategory.Error, "The_respective_set_accessor_has_the_type_0_2730", "The respective 'set' accessor has the type '{0}'."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b689b462a0468..1b540d3e355d3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22062,14 +22062,11 @@ namespace ts { const firstType = getAnnotatedType(first); const secondType = getAnnotatedType(second); if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) { - - if(isGetAccessor(first)){ - const typeNameFirstType = typeToString(firstType); - const typeNameSecondType = typeToString(secondType); + const typeNameFirstType = typeToString(firstType); + const typeNameSecondType = typeToString(secondType); - const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType); - diagnostic.relatedInformation = [createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)]; - } + const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType); + addRelatedInfo(diagnostic, createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)); } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9a0eb1208d211..05c0065296022 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2410,7 +2410,7 @@ "code": 2729 }, "The respective 'set' accessor has the type '{0}'.": { - "category": "Error", + "category": "Message", "code": 2730 }, diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt index be1c85374fb92..c0b2ff9328600 100644 --- a/tests/baselines/reference/abstractPropertyNegative.errors.txt +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type. -tests/cases/compiler/abstractPropertyNegative.ts(11,18): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +tests/cases/compiler/abstractPropertyNegative.ts(11,18): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'm' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'. @@ -31,10 +31,12 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors abstract m(): string; abstract get mismatch(): string; ~~~~~~~~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +!!! related TS2730 tests/cases/compiler/abstractPropertyNegative.ts:10:18: The respective 'set' accessor has the type 'number'. abstract set mismatch(val: number); // error, not same type ~~~~~~~~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! related TS2730 tests/cases/compiler/abstractPropertyNegative.ts:11:18: The respective 'set' accessor has the type 'string'. } class C extends B { ~ diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 99452b93d4763..6558f835a75d4 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5156,7 +5156,7 @@ declare namespace ts { Constructors_for_derived_classes_must_contain_a_super_call: DiagnosticMessage; A_get_accessor_must_return_a_value: DiagnosticMessage; Getter_and_setter_accessors_do_not_agree_in_visibility: DiagnosticMessage; - get_and_set_accessor_must_have_the_same_type: DiagnosticMessage; + get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1: DiagnosticMessage; A_signature_with_an_implementation_cannot_use_a_string_literal_type: DiagnosticMessage; Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: DiagnosticMessage; Overload_signatures_must_all_be_exported_or_non_exported: DiagnosticMessage; @@ -5432,6 +5432,7 @@ declare namespace ts { Cannot_find_lib_definition_for_0_Did_you_mean_1: DiagnosticMessage; _0_was_declared_here: DiagnosticMessage; Property_0_is_used_before_its_initialization: DiagnosticMessage; + The_respective_set_accessor_has_the_type_0: DiagnosticMessage; Import_declaration_0_is_using_private_name_1: DiagnosticMessage; Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; diff --git a/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt b/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt index a16cbfe7b37a5..af43224a671fb 100644 --- a/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt +++ b/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. ==== tests/cases/compiler/getAndSetNotIdenticalType.ts (4 errors) ==== @@ -10,12 +10,14 @@ tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType.ts:2:9: The respective 'set' accessor has the type 'string'. return 1; } set x(v: string) { } ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType.ts:5:9: The respective 'set' accessor has the type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt b/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt index c9fae8cc89c4a..e3340cf027364 100644 --- a/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt +++ b/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A' is not assignable to type 'A'. Type 'string' is not assignable to type 'T'. @@ -15,14 +15,16 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A', but this 'get' accessor has the type 'A'. +!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:5:9: The respective 'set' accessor has the type 'A'. return this.data; } set x(v: A) { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. +!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:8:9: The respective 'set' accessor has the type 'A'. this.data = v; ~~~~~~~~~ !!! error TS2322: Type 'A' is not assignable to type 'A'. diff --git a/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt b/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt index 3fb17d65a400b..00ae4ce2d00c2 100644 --- a/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt +++ b/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A' is not assignable to type 'A'. Type 'string' is not assignable to type 'number'. @@ -15,14 +15,16 @@ tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A', but this 'get' accessor has the type 'A'. +!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType3.ts:5:9: The respective 'set' accessor has the type 'A'. return this.data; } set x(v: A) { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. +!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType3.ts:8:9: The respective 'set' accessor has the type 'A'. this.data = v; ~~~~~~~~~ !!! error TS2322: Type 'A' is not assignable to type 'A'. diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 2a2dc7dd5753c..39a086a911755 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -71,11 +71,11 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,13): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: 'get' and 'set' accessor must have the same type. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,47): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,47): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type '4' is not assignable to type 'string'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: 'get' and 'set' accessor must have the same type. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55): error TS2380: 'get' and 'set' accessor must have the same type. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. ==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (78 errors) ==== @@ -268,15 +268,19 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) // Get and set accessor with mismatched type annotations var g1 = { get a(): number { return 4; }, set a(n: string) { } }; ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:42:16: The respective 'set' accessor has the type 'string'. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:42:47: The respective 'set' accessor has the type 'number'. var g2 = { get a() { return 4; }, set a(n: string) { } }; ~~~~~~~~~ !!! error TS2322: Type '4' is not assignable to type 'string'. var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:44:16: The respective 'set' accessor has the type 'string'. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:44:55: The respective 'set' accessor has the type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt b/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt index cd60967372353..d4ec08a5ca0aa 100644 --- a/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt +++ b/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt @@ -15,9 +15,11 @@ tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(11,9): err get x(this: Foo) { return this.n; }, ~ !!! error TS2682: 'get' and 'set' accessor must have the same 'this' type. +!!! related TS2730 tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts:10:9: The respective 'set' accessor has the type 'Bar'. set x(this: Bar, n) { this.wrong = "method"; } ~ !!! error TS2682: 'get' and 'set' accessor must have the same 'this' type. +!!! related TS2730 tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts:11:9: The respective 'set' accessor has the type 'Foo'. } const contextual: Foo = { n: 16, From d39e4246991eb6c4f65aaee03eb6eecb4026de03 Mon Sep 17 00:00:00 2001 From: bashdx Date: Fri, 6 Jul 2018 21:45:20 +0200 Subject: [PATCH 4/5] #25002: Implemented changes from feedback --- src/compiler/checker.ts | 11 +++++++---- src/compiler/diagnosticMessages.json | 2 +- .../abstractPropertyNegative.errors.txt | 10 +++------- .../reference/api/tsserverlibrary.d.ts | 2 +- .../getAndSetNotIdenticalType.errors.txt | 10 +++------- .../getAndSetNotIdenticalType2.errors.txt | 10 +++------- .../getAndSetNotIdenticalType3.errors.txt | 10 +++------- .../reference/objectLiteralErrors.errors.txt | 18 +++++------------- .../thisTypeInAccessorsNegative.errors.txt | 6 +----- 9 files changed, 27 insertions(+), 52 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b540d3e355d3..c6e7fa6099308 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22046,7 +22046,7 @@ namespace ts { // TypeScript 1.0 spec (April 2014): 4.5 // If both accessors include type annotations, the specified types must be identical. - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type_0); checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } @@ -22062,11 +22062,14 @@ namespace ts { const firstType = getAnnotatedType(first); const secondType = getAnnotatedType(second); if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) { - const typeNameFirstType = typeToString(firstType); const typeNameSecondType = typeToString(secondType); - const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType); - addRelatedInfo(diagnostic, createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)); + if(isGetAccessor(first)){ + + const diagnostic: Diagnostic = error(first, message, typeNameSecondType); + addRelatedInfo(diagnostic, createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)); + + } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 05c0065296022..415988577dc68 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1304,7 +1304,7 @@ "category": "Error", "code": 2379 }, - "'get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'.": { + "'get' and 'set' accessor must have the same type '{0}'.": { "category": "Error", "code": 2380 }, diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt index c0b2ff9328600..d2046652d4577 100644 --- a/tests/baselines/reference/abstractPropertyNegative.errors.txt +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -1,5 +1,4 @@ -tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. -tests/cases/compiler/abstractPropertyNegative.ts(11,18): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type 'number'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'm' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'. @@ -19,7 +18,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(40,9): error TS2676: Accessors tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors must both be abstract or non-abstract. -==== tests/cases/compiler/abstractPropertyNegative.ts (16 errors) ==== +==== tests/cases/compiler/abstractPropertyNegative.ts (15 errors) ==== interface A { prop: string; m(): string; @@ -31,12 +30,9 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors abstract m(): string; abstract get mismatch(): string; ~~~~~~~~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'number'. !!! related TS2730 tests/cases/compiler/abstractPropertyNegative.ts:10:18: The respective 'set' accessor has the type 'number'. abstract set mismatch(val: number); // error, not same type - ~~~~~~~~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. -!!! related TS2730 tests/cases/compiler/abstractPropertyNegative.ts:11:18: The respective 'set' accessor has the type 'string'. } class C extends B { ~ diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 6558f835a75d4..514311b110b8e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5156,7 +5156,7 @@ declare namespace ts { Constructors_for_derived_classes_must_contain_a_super_call: DiagnosticMessage; A_get_accessor_must_return_a_value: DiagnosticMessage; Getter_and_setter_accessors_do_not_agree_in_visibility: DiagnosticMessage; - get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1: DiagnosticMessage; + get_and_set_accessor_must_have_the_same_type_0: DiagnosticMessage; A_signature_with_an_implementation_cannot_use_a_string_literal_type: DiagnosticMessage; Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: DiagnosticMessage; Overload_signatures_must_all_be_exported_or_non_exported: DiagnosticMessage; diff --git a/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt b/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt index af43224a671fb..dc72501342d40 100644 --- a/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt +++ b/tests/baselines/reference/getAndSetNotIdenticalType.errors.txt @@ -1,23 +1,19 @@ tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: 'get' and 'set' accessor must have the same type 'string'. tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. -==== tests/cases/compiler/getAndSetNotIdenticalType.ts (4 errors) ==== +==== tests/cases/compiler/getAndSetNotIdenticalType.ts (3 errors) ==== class C { get x(): number { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string'. !!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType.ts:2:9: The respective 'set' accessor has the type 'string'. return 1; } set x(v: string) { } ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. -!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType.ts:5:9: The respective 'set' accessor has the type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt b/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt index e3340cf027364..2acc0538d40e1 100644 --- a/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt +++ b/tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt @@ -1,12 +1,11 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. +tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A'. tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A' is not assignable to type 'A'. Type 'string' is not assignable to type 'T'. -==== tests/cases/compiler/getAndSetNotIdenticalType2.ts (5 errors) ==== +==== tests/cases/compiler/getAndSetNotIdenticalType2.ts (4 errors) ==== class A { foo: T; } class C { @@ -15,16 +14,13 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A', but this 'get' accessor has the type 'A'. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'A'. !!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:5:9: The respective 'set' accessor has the type 'A'. return this.data; } set x(v: A) { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. -!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:8:9: The respective 'set' accessor has the type 'A'. this.data = v; ~~~~~~~~~ !!! error TS2322: Type 'A' is not assignable to type 'A'. diff --git a/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt b/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt index 00ae4ce2d00c2..75bb83fa8c0ac 100644 --- a/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt +++ b/tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt @@ -1,12 +1,11 @@ tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. +tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A'. tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A' is not assignable to type 'A'. Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/getAndSetNotIdenticalType3.ts (5 errors) ==== +==== tests/cases/compiler/getAndSetNotIdenticalType3.ts (4 errors) ==== class A { foo: T; } class C { @@ -15,16 +14,13 @@ tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A', but this 'get' accessor has the type 'A'. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'A'. !!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType3.ts:5:9: The respective 'set' accessor has the type 'A'. return this.data; } set x(v: A) { ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'A', but this 'get' accessor has the type 'A'. -!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType3.ts:8:9: The respective 'set' accessor has the type 'A'. this.data = v; ~~~~~~~~~ !!! error TS2322: Type 'A' is not assignable to type 'A'. diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 39a086a911755..3987a8dc003de 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -71,14 +71,12 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,13): error TS2300: Duplicate identifier 'a'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS2300: Duplicate identifier 'a'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,47): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: 'get' and 'set' accessor must have the same type 'string'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type '4' is not assignable to type 'string'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: 'get' and 'set' accessor must have the same type 'string'. -==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (78 errors) ==== +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (76 errors) ==== // Multiple properties with the same name var e1 = { a: 0, a: 0 }; ~ @@ -268,19 +266,13 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55) // Get and set accessor with mismatched type annotations var g1 = { get a(): number { return 4; }, set a(n: string) { } }; ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string'. !!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:42:16: The respective 'set' accessor has the type 'string'. - ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. -!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:42:47: The respective 'set' accessor has the type 'number'. var g2 = { get a() { return 4; }, set a(n: string) { } }; ~~~~~~~~~ !!! error TS2322: Type '4' is not assignable to type 'string'. var g3 = { get a(): number { return undefined; }, set a(n: string) { } }; ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'. +!!! error TS2380: 'get' and 'set' accessor must have the same type 'string'. !!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:44:16: The respective 'set' accessor has the type 'string'. - ~ -!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'. -!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:44:55: The respective 'set' accessor has the type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt b/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt index d4ec08a5ca0aa..e6f09020db19d 100644 --- a/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt +++ b/tests/baselines/reference/thisTypeInAccessorsNegative.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(10,9): error TS2682: 'get' and 'set' accessor must have the same 'this' type. -tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(11,9): error TS2682: 'get' and 'set' accessor must have the same 'this' type. -==== tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts (2 errors) ==== +==== tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts (1 errors) ==== interface Foo { n: number; x: number; @@ -17,9 +16,6 @@ tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts(11,9): err !!! error TS2682: 'get' and 'set' accessor must have the same 'this' type. !!! related TS2730 tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts:10:9: The respective 'set' accessor has the type 'Bar'. set x(this: Bar, n) { this.wrong = "method"; } - ~ -!!! error TS2682: 'get' and 'set' accessor must have the same 'this' type. -!!! related TS2730 tests/cases/conformance/types/thisType/thisTypeInAccessorsNegative.ts:11:9: The respective 'set' accessor has the type 'Foo'. } const contextual: Foo = { n: 16, From 1d968abf55591d42251f395d8af4a5be2b08301f Mon Sep 17 00:00:00 2001 From: bashdx Date: Sat, 7 Jul 2018 21:52:31 +0200 Subject: [PATCH 5/5] #25002: removed unneccessary newlines --- src/compiler/checker.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c6e7fa6099308..aefe71c97871f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22063,12 +22063,9 @@ namespace ts { const secondType = getAnnotatedType(second); if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) { const typeNameSecondType = typeToString(secondType); - if(isGetAccessor(first)){ - const diagnostic: Diagnostic = error(first, message, typeNameSecondType); addRelatedInfo(diagnostic, createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)); - } } }