Skip to content

[AST] Restore getSourceRange() on DefaultArgumentExpr #31861

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

Merged
merged 1 commit into from
May 19, 2020

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented May 18, 2020

This restores getSourceRange() on DefaultArgumentExpr after it was removed in
#31184.

It was originally removed to solve the issues it was causing when computing the source range of its parent TupleExpr. To account for trailing closures we walk back through the tuple's arguments until one with a valid location is found, which we use as the end location. If the last argument was a DefaultArgumentExpr though that meant the end loc would end up being the tuple's start location, so none of the tuple's other arguments were contained in its range, triggering an
ASTVerifier assertion. Source tooling and diagnostics don't care about default arg expression locations as nothing can reference them on the caller side and any issues in them should be reported on the callee side, but their locations are output in the debug info. Added a regression test to catch that in future, and updated TupleExpr::getSourceRange() to ignore DefaultArgumentExprs when computing the end loc.

Resolves rdar://problem/63195504.

@nathawes nathawes requested a review from xedin May 18, 2020 16:57
@nathawes
Copy link
Contributor Author

@swift-ci please test

This restores getSourceRange() on DefaultArgumentExpr after it was removed in
swiftlang#31184.

It was originally removed to solve the issues it was causing when computing the
source range of its parent TupleExpr. To account for trailing closures we walk
back through the tuple's arguments until one with a valid location is found,
which we use as the end location. If the last argument was a DefaultArgumentExpr
though that meant the end loc would end up being the tuple's start location, so
none of the tuple's other arguments were contained in its range, triggering an
ASTVerifier assertion. Source tooling and diagnostics don't care about default
arg expression locations as nothing can reference them, but their locations are
output in the debug info. Added a regression test to catch that in future, and
updated TupleExpr::getSourceRange() to ignore them when computing the end loc.

Resolves rdar://problem/63195504.
@nathawes nathawes force-pushed the default-arg-location-source-loc branch from ba946e5 to 94916de Compare May 18, 2020 21:52
@nathawes nathawes requested a review from xedin May 18, 2020 21:58
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ba946e580b3f1792c2b6a77c78337684bee693a6

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ba946e580b3f1792c2b6a77c78337684bee693a6

@nathawes nathawes changed the title [AST] Restore getLoc() on DefaultArgumentExpr [AST] Restore getSourceRange() on DefaultArgumentExpr May 18, 2020
@nathawes nathawes merged commit 0e008e0 into swiftlang:master May 19, 2020
@nathawes nathawes deleted the default-arg-location-source-loc branch May 19, 2020 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants