-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expression syntax and semicolon #1712
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
Comments
I'm not sure I understand the question. If x is used in a context that expects a type other than nil, the second version of the code would be a type error, because all of the if branches have type nil (the trailing semicolon says "do this and throw away the result", so the blocks all have type nil). Maybe I'm missing something, though? |
@catamorphism It is actually not an error if x is assigned to nil type like the last example above. Or, are we going to change this? |
@lht Yes, it's not an error, but it would be an error to use x (except by, say, passing it to a function that had an argument of type nil, but you probably would never write such a function). I'm still not exactly sure what the situation is that you're worried about that would be confusing -- can you explain further, maybe with a code example for the part of the code that uses x? |
I think semicolons in the expression syntax should be forbidden (maybe in the phase of semantics analysis) since |
See also #1195, which suggests adding better compiler warning or error messages. |
I don't see this as a problem. We are certainly not going to prohibit semicolons in blocks. They are very useful. I could see a warning if some branches of an if or alt have no tail expression while others do, though I am inclined against it as any real problem will be caught by type checker. I am going to close this issue but feel free to add to #1195 concerning a warning if you feel that would be appropriate. Sent via Hubroid |
Hi, I'm a Rust language newbie so what I mention below may be non-sense. :-)
I think it is not that wise to make use of semicolon (;) as the separator between statements along with the expression syntax provided in the language, because it will potentially lead to many typo-caused bugs. For example, for the following snippet from the Rust language tutorial:
If the expressions inside the braces are function calls, it would be harder to decide:
and
The text was updated successfully, but these errors were encountered: