-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Better error message for accidental calls to get-accessors #37800
Merged
sandersn
merged 8 commits into
microsoft:master
from
jtbandes:diagnose-accidental-accessor-call
May 21, 2020
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61f6005
Better error message for accidental calls to get-accessors
jtbandes d00a5c9
Add _0_is_declared_here pointing to accessor declaration
jtbandes d00f2b5
replace the original not-callable error
jtbandes 6051fc1
move to invocationErrorDetails
jtbandes fd4ecce
Merge remote-tracking branch 'upstream/master' into diagnose-accident…
jtbandes 0b1cb74
fix order and tests
jtbandes fc83d10
Merge branch 'master' into diagnose-accidental-accessor-call
sandersn 0b53172
Make new error an error, not message
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? | ||
Type 'Number' has no call signatures. | ||
|
||
|
||
==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/24554 | ||
class Test24554 { | ||
get property(): number { return 1; } | ||
} | ||
function test24554(x: Test24554) { | ||
return x.property(); | ||
~~~~~~~~ | ||
!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? | ||
!!! message TS6234: Type 'Number' has no call signatures. | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/accessorAccidentalCallDiagnostic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [accessorAccidentalCallDiagnostic.ts] | ||
// https://github.com/microsoft/TypeScript/issues/24554 | ||
class Test24554 { | ||
get property(): number { return 1; } | ||
} | ||
function test24554(x: Test24554) { | ||
return x.property(); | ||
} | ||
|
||
|
||
//// [accessorAccidentalCallDiagnostic.js] | ||
// https://github.com/microsoft/TypeScript/issues/24554 | ||
var Test24554 = /** @class */ (function () { | ||
function Test24554() { | ||
} | ||
Object.defineProperty(Test24554.prototype, "property", { | ||
get: function () { return 1; }, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Test24554; | ||
}()); | ||
function test24554(x) { | ||
return x.property(); | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/accessorAccidentalCallDiagnostic.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
=== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts === | ||
// https://github.com/microsoft/TypeScript/issues/24554 | ||
class Test24554 { | ||
>Test24554 : Symbol(Test24554, Decl(accessorAccidentalCallDiagnostic.ts, 0, 0)) | ||
|
||
get property(): number { return 1; } | ||
>property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17)) | ||
} | ||
function test24554(x: Test24554) { | ||
>test24554 : Symbol(test24554, Decl(accessorAccidentalCallDiagnostic.ts, 3, 1)) | ||
>x : Symbol(x, Decl(accessorAccidentalCallDiagnostic.ts, 4, 19)) | ||
>Test24554 : Symbol(Test24554, Decl(accessorAccidentalCallDiagnostic.ts, 0, 0)) | ||
|
||
return x.property(); | ||
>x.property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17)) | ||
>x : Symbol(x, Decl(accessorAccidentalCallDiagnostic.ts, 4, 19)) | ||
>property : Symbol(Test24554.property, Decl(accessorAccidentalCallDiagnostic.ts, 1, 17)) | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/accessorAccidentalCallDiagnostic.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
=== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts === | ||
// https://github.com/microsoft/TypeScript/issues/24554 | ||
class Test24554 { | ||
>Test24554 : Test24554 | ||
|
||
get property(): number { return 1; } | ||
>property : number | ||
>1 : 1 | ||
} | ||
function test24554(x: Test24554) { | ||
>test24554 : (x: Test24554) => any | ||
>x : Test24554 | ||
|
||
return x.property(); | ||
>x.property() : any | ||
>x.property : number | ||
>x : Test24554 | ||
>property : number | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @target: es5 | ||
|
||
// https://github.com/microsoft/TypeScript/issues/24554 | ||
class Test24554 { | ||
get property(): number { return 1; } | ||
} | ||
function test24554(x: Test24554) { | ||
return x.property(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should be an Error, not a Message.