Skip to content

improve Diagnostics for accidentally calling type-assertion expressions#27020

Merged
DanielRosenwasser merged 2 commits into
microsoft:masterfrom
Kingwl:improve_accidentally_calling_type-assertion_expressions
Sep 11, 2018
Merged

improve Diagnostics for accidentally calling type-assertion expressions#27020
DanielRosenwasser merged 2 commits into
microsoft:masterfrom
Kingwl:improve_accidentally_calling_type-assertion_expressions

Conversation

@Kingwl
Copy link
Copy Markdown
Contributor

@Kingwl Kingwl commented Sep 11, 2018

Fixes #26991

@Kingwl
Copy link
Copy Markdown
Contributor Author

Kingwl commented Sep 11, 2018

maybe that could be a related Diagnostics?

Copy link
Copy Markdown
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and great test cases! Can we make this a related span though?

Comment thread src/compiler/checker.ts Outdated
else {
if (node.arguments.length === 1 && isTypeAssertion(first(node.arguments))) {
const text = getSourceFileOfNode(node).text;
const pos = skipTrivia(text, node.expression.end, /* stepAfterLineBreak */ true) - 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step -> stop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this function and isLineBreak seem to have differing definitions of what a line break is...

...so I don't know if that's a problem 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in CRLF or LF, the skipTrivia() - 1 will always correctly,
but if only CR, that seems a problem...

Comment thread src/compiler/checker.ts Outdated
const text = getSourceFileOfNode(node).text;
const pos = skipTrivia(text, node.expression.end, /* stepAfterLineBreak */ true) - 1;
if (isLineBreak(text.charCodeAt(pos))) {
error(node.expression, Diagnostics.It_is_highly_likely_that_you_are_missing_a_semicolon);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! This should definitely be a related span if possible.

@DanielRosenwasser DanielRosenwasser merged commit aa9230f into microsoft:master Sep 11, 2018
@DanielRosenwasser
Copy link
Copy Markdown
Member

Thanks @Kingwl!

@Kingwl Kingwl deleted the improve_accidentally_calling_type-assertion_expressions branch September 12, 2018 00:45
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants