You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function f(int x) -> (int r):
switch(x):
case 1:
return 0
case 1:
return 1
The above should generate a "duplicate case label" error message (E509). At the moment, the job of checking for duplicate case labels is left to CodeGenerator. Realistically, it should come earlier in the pipeline.
The reason that checking for duplicate case labels comes earlier is that it's only after FlowTypeChecker that we know what the constant values resolve to. However, this does raise the question as to whether we should be looking at the source-level syntax or the underlying value. Java, for example, only looks at the souce-level syntax. So the following compiles without problem:
switch(x) {
case 1+1:
return 0;
case 1-1:
return 1;
}
Some thought is really needed as to what the right decision is here.
The text was updated successfully, but these errors were encountered:
Where possible I have removed syntax checks from CodeGenerator, as this
is not the place where we should be doing this. In some cases, things
have just disappeared. In other cases, I've left some internal failures
instead.
Unfortunately, the issue of checking duplicate case labels (E509) needs
further thought. I've opened a separate issue for this #628
Previously, the checks for determining whether a break or continue statement was
contained within a loop were performed in CodeGenerator. This is not the right
place to do these checks, and I have now moved them into the parser. In doing
this, I refactored the parser a little which has improved it nicely.
At this stage, the only remaining syntax check in CodeGenerator is for duplicate
case labels. This is a little trickier to decide upon, and is left for #628
Consider the following program:
The above should generate a "duplicate case label" error message (E509). At the moment, the job of checking for duplicate case labels is left to
CodeGenerator
. Realistically, it should come earlier in the pipeline.The reason that checking for duplicate case labels comes earlier is that it's only after
FlowTypeChecker
that we know what the constant values resolve to. However, this does raise the question as to whether we should be looking at the source-level syntax or the underlying value. Java, for example, only looks at the souce-level syntax. So the following compiles without problem:Some thought is really needed as to what the right decision is here.
The text was updated successfully, but these errors were encountered: