Skip to content

[SR-510][Parser] complain for invalid enum raw value #955

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 4 commits into from
Jan 15, 2016

Conversation

dduan
Copy link
Contributor

@dduan dduan commented Jan 13, 2016

Instead of fail silently, issue a diagosis when a valid expression can not
be parsed for enum raw value.

Resolves SR-510.

dduan added 2 commits January 13, 2016 01:10
Instead of fail silently, issue a diagosis when a valid expression can not
be parsed for enum raw value.

This resolves [SR-510](https://bugs.swift.org/browse/SR-510).
@jrose-apple
Copy link
Contributor

This seems reasonable, but (a) is it possible to use the loc of the first token after the equal sign instead, and (b) what happened to the other issue about parsing a closure? That still seems like a better fix for this particular unparseable expression.

@dduan
Copy link
Contributor Author

dduan commented Jan 13, 2016

Hi @jrose-apple,

(a) is it possible to use the loc of the first token after the equal sign instead

done.

(b) what happened to the other issue about parsing a closure? That still seems like a better fix for this particular unparseable expression.

I agree with your verdict. #934 could fix a number of unforeseen issues (wherever a closure is defined without a context). That said, this approach has a similar benefit: it catches all cases where the parseExpr fails. There could be more besides closure. IMHO this PR addresses SR-510 more directly.

@dduan
Copy link
Contributor Author

dduan commented Jan 14, 2016

I think we can just reuse the regular diagnostic (nonliteral_enum_case_raw_value). That's what they need to correct to anyway.

Didn't notice this one util now. Done.

Do we know of anything else that will trigger this error?

None to the best of my knowledge.

I would guess the reason we didn't diagnose anything here before is because anything else would get its own diagnostic first anyway.

That makes an argument for this type of catch-all fix IMO. It's always hard to prove something doesn't exist 😛.

(it's still valuable to find all edge cases. If the context-less closure parsing causes other bugs, we would fix it then).

@jrose-apple

@lattner
Copy link
Contributor

lattner commented Jan 15, 2016

This looks good to me. Please email swift-dev to see if Ted will approve pulling this into Swift 2.2, thanks!

lattner added a commit that referenced this pull request Jan 15, 2016
[SR-510][Parser] complain for invalid enum raw value
@lattner lattner merged commit bce19d4 into swiftlang:master Jan 15, 2016
dduan added a commit to dduan/swift that referenced this pull request Jan 15, 2016
lattner added a commit that referenced this pull request Jan 15, 2016
fix raw value error test introduced in #955
@jrose-apple
Copy link
Contributor

I'd argue that this diagnostic should be an assertion, then, not a separate diagnostic. In the common case here, we'll get duplicate error messages, and this one doesn't add any value.

@dduan
Copy link
Contributor Author

dduan commented Jan 15, 2016

Fair. To avoid the duplicate message, we could do one of the following:

  1. Let parseExpr know it's working on a raw value. Give closure parser a context somehow.
  2.  use parseExrBasic instead of parseExpr. In theory, this will skip closure parsing.
  3. Detect the closure pattern outside of parseExpr. This might duplicate a little bit of code.
    I'll try all these and report back.
  • Daniel Duan

On Fri, Jan 15, 2016 at 8:41 AM -0800, "Jordan Rose" notifications@github.com wrote:

I'd argue that this diagnostic should be an assertion, then, not a separate diagnostic. In the common case here, we'll get duplicate error messages, and this one doesn't add any value.


Reply to this email directly or view it on GitHub.

@jrose-apple
Copy link
Contributor

I really just want to parse the closure successfully and then error successfully, as discussed in #934.

@jder
Copy link
Contributor

jder commented Jan 24, 2016

@dduan Are you still working on this? If so, let me know and I will assign the bug to you.

FWIW, I think this can also happen for at least a couple other cases:

#if {}

and

typealias foo = (Int = {})

@dduan
Copy link
Contributor Author

dduan commented Jan 24, 2016

Hi, @jder. @jrose-apple has been helping me with #987. But from what you posted here, that fix may not be general enough.

@jder
Copy link
Contributor

jder commented Jan 24, 2016

@dduan OK, I'm going to assign you the bug and stop working on it, then. My WIP is here, if you'd like to grab anything from it: master...jder:parse-closures-dummy-localcontext. It catches some cases but still not all of them.

@dduan dduan deleted the SR-510-2 branch December 23, 2019 21:49
MaxDesiatov added a commit to MaxDesiatov/swift that referenced this pull request May 11, 2020
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