-
Notifications
You must be signed in to change notification settings - Fork 416
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
improve diagnostic for unnamed closure parameters #2727
improve diagnostic for unnamed closure parameters #2727
Conversation
@bnbarham would you mind reviewing this PR too? :) |
e0533a8
to
3d54574
Compare
Updated, please have a look. |
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.
Thank you @AppAppWorks. Looks great!
@swift-ci Please test |
@ahoppen I've found that some of my code comments are misleading and the test case for missing both identifier and type is missing. I've rewritten the comments and added a new test case as follows, if you also think they're necessary and good, I'll force-commit again. let names = self.parseParameterNames()
var colon = self.consume(if: .colon)
// try to parse the type regardless of the presence of the preceding colon
// to tackle any unnamed parameter or missing colon
// e.g. [X], (:[X]) or (x [X])
let canParseType = withLookahead { $0.canParseType() }
let type: RawTypeSyntax?
if canParseType {
type = self.parseType(misplacedSpecifiers: misplacedSpecifiers)
if colon == nil {
// mark the preceding colon as missing if the type is present
// e.g. [X] or (x [X])
colon = missingToken(.colon)
}
} else if colon != nil {
// mark the type as missing if the preceding colon is present
// e.g. (:) or (_:)
type = RawTypeSyntax(RawMissingTypeSyntax(arena: self.arena))
} else {
type = nil
} assertParse(
"""
test { (1️⃣:2️⃣) in }
""",
diagnostics: [
DiagnosticSpec(
locationMarker: "1️⃣",
message: "expected identifier in parameter",
fixIts: ["insert identifier"]
),
DiagnosticSpec(
locationMarker: "2️⃣",
message: "expected type in parameter",
fixIts: ["insert type"]
),
],
fixedSource: """
test { (<#identifier#>: <#type#>) in }
"""
) |
Force push your improved changes and I’ll review them again. |
- instead of treating as unrecognized, try to parse the remaining tokens as a type even if the preceding colon is missing
Head branch was pushed to by a user without write access
3d54574
to
55cd304
Compare
Pushed, please check. |
@swift-ci Please test |
fix #2340