Skip to content

Report error on method name for chained method calls - #31414

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 5 commits into
microsoft:masterfrom
dhruvrajvanshi:master
Jun 22, 2019
Merged

Daniel Rosenwasser (DanielRosenwasser) merged 5 commits into
microsoft:masterfrom
dhruvrajvanshi:master

Conversation

@dhruvrajvanshi

Copy link
Copy Markdown
Contributor

Fixes #31365

This is a first stab at fixing the issue. It reports the error at the name of the final method call.

Ideally, the error would be reported at the argument list span for the call but I couldn't find a straightforward way to get a span for the argument list. I'm willing to the PR if we really need reporting at the argument list.

declare const xAny: X<any>;
xAny.f() // error, any still expects an argument
~~~~~~~~
~

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 think the idea was that the argument list was supposed to be included in the range.

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.

Ah, just saw your comment in the PR.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented May 15, 2019 •

Copy link
Copy Markdown
Member

Spoke with Ryan Cavanaugh (@RyanCavanaugh) - we think just erroring on the name itself is fine, but we'd like to error on the invoked expression itself even when it's not a property access. In other words, if you don't have a property access as the target, use node.expression for the error span.

@dhruvrajvanshi

Copy link
Copy Markdown
Contributor Author

Daniel Rosenwasser (@DanielRosenwasser) I'm not quite sure I understand.
Do you mean something like this?

function getCallErrorNode(node: CallLikeExpression): Node {
        if (isCallExpression(node)) {
            if (isPropertyAccessExpression(node.expression)) {
                return node.expression.name;
            } else {
                return node.expression
            }
        }
                
        return node;
}

Because this is breaking a lot of error messages (and they look worse IMO).

Ideally, the error should include the final method name and its argument list which could be done by including a span in NodeArray.

@DanielRosenwasser

Copy link
Copy Markdown
Member

Yeah, something like that code.

Because this is breaking a lot of error messages (and they look worse IMO).

Maybe we'd do this for only Identifier nodes. What looks grosser?

@dhruvrajvanshi

Copy link
Copy Markdown
Contributor Author

I've updated the PR so you can see for yourself. Most call argument arity errors exclude the argument list. It is more uniform with the new change though.

Is there a way to report diagnostics on spans instead of nodes?

@DanielRosenwasser

Copy link
Copy Markdown
Member

I think this is a great first step. If we want to iterate further, we'll take another PR.

@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) merged commit 2c458c0 into microsoft:master Jun 22, 2019
Titian Cernicova-Dragomir (dragomirtitian) added a commit to dragomirtitian/TypeScript4ExtJS that referenced this pull request Jun 28, 2019
1. When calling a non-callable expression the error span is on the call target not on the whole call
2. When calling a method, the error for overload resolution now includes the arguments (this was previously regressed by microsoft#31414)
Titian Cernicova-Dragomir (dragomirtitian) added a commit to dragomirtitian/TypeScript4ExtJS that referenced this pull request Jun 28, 2019
1. When calling a non-callable expression the error span is on the call target not on the whole call
2. When calling a method, the error for overload resolution now includes the arguments (this was previously regressed by microsoft#31414)
@microsoft 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

2 participants