-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added implementation for issue #25002 #25415
Conversation
@@ -6323,7 +6323,7 @@ | |||
</Item> | |||
<Item ItemId=";get_and_set_accessor_must_have_the_same_type_2380" ItemType="0" PsrId="306" Leaf="true"> | |||
<Str Cat="Text"> | |||
<Val><![CDATA['get' and 'set' accessor must have the same type.]]></Val> | |||
<Val><![CDATA['get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'.]]></Val> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is auto generated as part of the build. do not change it manually.
lib/tsc.js
Outdated
@@ -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."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. just revert changes to all files under lib*
src/compiler/checker.ts
Outdated
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)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use addRelatedInfo instead.
src/compiler/diagnosticMessages.json
Outdated
@@ -2401,6 +2401,10 @@ | |||
"category": "Error", | |||
"code": 2728 | |||
}, | |||
"The respective 'set' accessor has the type '{0}'.": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanielRosenwasser any comments on the message text?
src/compiler/diagnosticMessages.json
Outdated
@@ -2401,6 +2401,10 @@ | |||
"category": "Error", | |||
"code": 2728 | |||
}, | |||
"The respective 'set' accessor has the type '{0}'.": { | |||
"category": "Error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be "Message"
and not "Error"
You need to run the tests |
Just FYI, please check the result. When I changed the code so that the result only displayed the getter the unit tests resulted in an error (expected 3 errors, but got 2).
The statement about the 'set' accessor in the first line is wrong. How to proceed? |
@@ -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'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the elaboration `but this 'get' accessor has the type 'string' is not needed. adding a related info is sufficient.
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'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this elaboration should be different, it should be about the get
and not the set
since this error is already about the set
accessor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mentioned in my most recent comment above. As of now (with passing tests) the messages are shown twice and the second message is actually garbage. If I test only for the getter the output looks as desired (that's what I presume), but the tests fail.
So what do we do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i understand what you mean by "but the tests fail."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests from jake runtests-parallel
fail.
If I implement the function this way:
function checkAccessorDeclarationTypesIdentical(first: AccessorDeclaration, second:
AccessorDeclaration, getAnnotatedType: (a: AccessorDeclaration) => Type | undefined, message: DiagnosticMessage) {
const firstType = getAnnotatedType(first);
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));
}
}
}
The output looks like this:
test_accessors.ts:3:9 - error TS2380: 'get' and 'set' accessor must have the same type 'string'.
3 get foo(): number { return 100; }
~~~
test_accessors.ts:3:9
3 get foo(): number { return 100; }
~~~
The respective 'set' accessor has the type 'string'.
This is how I would expect the output to look like. But now the unit tests fail:
jake runtests-parallel
node lib/tsc.js -b src
node built/local/tsc.js -b built/local/typescriptServices.tsconfig.json
cp -r built/local/typescriptServices.js built/local/typescript.js
cp -r built/local/typescriptServices.js.map built/local/typescript.js.map
node lib/tsc.js -b src/testRunner
node built/local/run.js
Discovered 134 unittest suites.
Discovering runner-based tests...
Discovered 12550 test files in 672ms.
Starting to run tests using 4 threads...
Batching initial test lists...
Batched into 4 groups with approximate total file sizes of 2457413 bytes in each group. (99.6% of total tests batched)
[▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․] 3 failing
[Worker 0] Unexpected error(s) found. Error list is:
[Worker 0] from: 1:8, to: 1:10, message: 'get' and 'set' accessor must have the same type 'number'.
[Worker 0] from: 5:8, to: 5:9, message: Type '"30"' is not assignable to type 'number'.
Actual number of errors (2) does not match expected number (3)
[▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬] ✖ 61200/61208 passing (5m)
What to make of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are baseline tests, so they will fail every time the output changes. and that is fine.
change the message, then run the tests (jake runtests-parallel
), then accept the new baselines (jake baseline-accept
).
@DanielRosenwasser can you please review the error message changes.. |
src/compiler/checker.ts
Outdated
const typeNameSecondType = typeToString(secondType); | ||
|
||
if(isGetAccessor(first)){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove newline.
@@ -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}'.": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking
Accessors must have identical types, but this 'get' accessor has type '{0}' and its respective 'set' accessor has type '{1}'.
with
The respective 'set' accessor is declared here.
However, to be honest, I'm not sure how I feel about this change; I feel like the simpler error message was actually better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just the the 'set' accessor is declared here:
I removed the newlines, what's next? |
@DanielRosenwasser do we need this? |
@bashdx if you can get the conflicts resolved and the CI green, I think we can merge this |
@@ -15,14 +14,13 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A<s | |||
~ | |||
!!! 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<string>'. | |||
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:5:9: The respective 'set' accessor has the type 'A<string>'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should not repeat the same type in each message
Closing due to lack of activity and outstanding merge conflicts/CI failures. If anyone's looking at picking this up again, please refer to comments here and on the issue before proceeding - it's not super clear what the best error experience is and it'd be good to establish what a positive outcome looks like first. |
Fixes #
Changed error message for get and set accessors having different types. Also adding a related span with further explanations.