Closed jvasileff closed 9 years ago
I disagree. (x)++
and (x) = x
are syntactically legal expressions, even though the typechecker rejects them. Remember, we don’t care about semantics.
(I think there’s an example in some node where the documentation explicitly says something like “for legal, well-typed code this value must always be X”, but I can’t find it now.)
Maybe you mean the notes on AssignmentStatement:
In principle, a statement like i = 0; could be parsed ambigously, either as an assignment statement or as a specification. When possible, the Ceylon language favors the latter interpretation, which means that an assignment statement where the target is a BaseExpression is invalid. (This is only true for simple AssignOperations; other assignment operations, e. g. i += size;, are still valid assignment expression statements.)
Ok, I guess you're right. But I'm still going to try to find a logical justification for the change :smile:
Maybe you mean the notes on AssignmentStatement:
In principle, a statement like i = 0; could be parsed ambigously, either as an assignment statement or as a specification. When possible, the Ceylon language favors the latter interpretation, which means that an assignment statement where the target is a BaseExpression is invalid. (This is only true for simple AssignOperations; other assignment operations, e. g. i += size;, are still valid assignment expression statements.)
No, that’s actually something we prevent – we throw an assertion error in the ambiguous case:
if (is AssignOperation expression) {
"An assignment statement with a simple assign operation
where the target expression is a simple base expression
must instead be expressed as a value specification"
assert (!expression.target is BaseExpression);
}
Actually, I guess there can be no justification for this if it's syntactically valid. I'll go ahead and close it. Thanks for the info.
Unless I'm missing something, we should be able to use
BaseExpression | QualifiedExpression
as the left operand type for:AssignmentOperation
PrefixOperation
PostfixOperation
See: