Skip to content
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

Syntax Checks for Duplicate Case Labels #628

Closed
DavePearce opened this issue Apr 20, 2016 · 0 comments
Closed

Syntax Checks for Duplicate Case Labels #628

DavePearce opened this issue Apr 20, 2016 · 0 comments

Comments

@DavePearce
Copy link
Member

Consider the following program:

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.

@DavePearce DavePearce added this to the ChangeList Post v0.4.0 milestone Apr 20, 2016
DavePearce added a commit that referenced this issue Apr 20, 2016
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
DavePearce added a commit that referenced this issue Apr 20, 2016
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
@DavePearce DavePearce removed the WYC label Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant