-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add syntax fixup for while loops #12880
Conversation
Thanks for looking into this! We should only add the curly braces if they're missing, similar to how we do it for |
@flodiebold Thanks for the hints! I added the test cases you asked for, but there's something weird happening in
It seems like the curly braces are parsed both as the condition and the loop body. |
Oh... yeah, currently for pub fn condition(&self) -> Option<Expr> {
let mut exprs = support::children(self.syntax());
let first = exprs.next();
let second = exprs.next();
if let Some(ast::Expr::BlockExpr(_)) = first {
second.and(first)
} else {
first
}
} i.e. if the first expression is a block expression, only consider it as the condition if there's also a second one (i.e. the loop body). This would live in an |
Hmm, I would expect with |
Yeah, but it's less common to use blocks for the condition (oh, hello there!), isn't it? In practice I suspect it doesn't matter. |
It certainly doesn't matter for this, but it might matter for some other features like completion? In any case, I think treating the |
Ye, that's the thing. It's barely used so assuming the condition is what's missing helps more in the general case I'd say let's special case it. In any case, we'll have to add This will also require |
Some of the things you've been discussing are over my head for now and should probably be split out in a new issue. Would it be ok to remove the test case in question and wait until the underlying issue is fixed? |
#12890 should address the syntax tree problems, that is we no longer should be treating a single expression as both the condition and the body |
internal: Assume condition/iterable is missing if there is only a BlockExpr cc #12880 (comment) It sounds good on paper, so let's try it
Thanks for the quick fix, that solved the problem. |
Thanks! |
☀️ Test successful - checks-actions |
Part of #12777
This is a first iteration to gather some feedback. In particular I'm not sure if the curly braces should be added here, but I couldn't get the test to work without them. Any hints welcome!