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
[SR-2442] Need better diagnostics for multi-value assignment with missing parens #45047
Comments
I've confirmed that this is still an issue on the release version of Swift 3.0.1. Assuming it still happens on master, I'd like to try my hand at this. If I'm not done by January someone feel free to steal it back from me. 🙂 |
Hello again! This is my first foray into the parser, and I wouldn't mind a little help. 🙂 I've found two spots where the parser could potentially recover, but I'd appreciate feedback on how I'm approaching the problem/solution. Reducing the problem a bit, I noticed that
I'm not sure this approach makes sense, because I'm still learning how the parser maintains state in the first place. To get into specifics, my understanding of the parsing occurring here is:
I can see two potential spots to add better diagnostics:
The part that I'm currently stuck on is: in both of these approaches, once I've noticed that I'm parsing what should be a tuple, how do I "backtrack?" I noticed some code that calls That's about as far as I've gotten so far. I have some questions:
|
Friendly ping! /cc @jtbandes As someone new to the parser, I'm not entirely sure if this is achievable. Specifically, it seems hard to determine where to place a, b, c = c, a, b To a human being, it seems obvious that this should be Then again, this is my first venture into the parsing code at all, so I absolutely expect to be missing something. Any advice, @jtbandes? |
Also +cc other parser aficionados, like @rintaro and CodaFi (JIRA User). Any tips, or even just a "this is possible to implement" stamp of approval? |
First of all, this is not a
Yeah, that is the most difficult problem in this issue. Because of this, the diagnostics would definitely be highly speculative, Also, we must take care of other constructs such as: if <expr>, <expr> { ... }
let cb: (Int, Int) -> Void = { [x = <expr>, y = <expr>] a, b -> Void in ... } I think the simplest solution would be modifying Add (sequence_expr
(tuple_expr implicit
(<expr1>) // ,
(<expr2>))
(assign_expr) // =
(tuple_expr implicit
(sequence_expr
(<expr3>)
(unresolved_decr_ref_expr name=+) // +
(<expr4>)
(unresolved_decr_ref_expr name=-) // -
(<expr5>)) // ,
(sequence_expr
(<expr6>)
(unresolved_decr_ref_expr name=??) // ??
(<expr7>)))) You can emit error diagnostics with fix-it when constructing implicit I think, you can ignore "mutability" of LHS(s), or difference of num of elements between LHS and RHS. Disclaimer: I'm not 100% sure about this strategy 😛 |
You could also consider |
Ah, Rintaro is right, I guess the TupleShuffle is only produced during type checking. It's just a SequenceExpr during parsing. |
Awesome, thanks so much for the explanations. This definitely seems like more than I can accomplish in the next few weeks, so I'll put it back up for grabs. I'll try to build up my skills with other, smaller parser tasks first, then revisit this later. I also removed the "StarterBug" label – although it was a very good prompt to explore a lot of the parser code, so: thank you! (And this definitely seems like a really great diagnostic to have, I'm excited to see someone take it on.) |
Re: backtracking, you can also find some places where I think you're on the right track in general 🙂 I definitely had to struggle through skimming lots of parser/typechecker code when I began working on these sorts of bugs (and I still do, every time — it's such a large component). From your analysis it sounds like you've figured out the general workflow of tracing through where various expressions are first created / the decisions being made by the parser along the way. Test cases will be interesting too. |
You may have an easier time fixing bugs to start with, rather than adding "features" like new diagnostics 😉 |
Even var a: ()
var b: Int
var c: Int
let d: (Int, Int) = (12, 34)
a = (b, c) = d Hmm, |
@swift-ci create |
Additional Detail from JIRA
md5: 0eb677a1105f260bac228341f2e71d33
Issue Description:
Given
var a = 1, b = 2
, in some other languages you can swap them withThe text was updated successfully, but these errors were encountered: