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

fix switch with default stmt before case stmt #106

Merged
merged 1 commit into from
Feb 17, 2023
Merged

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Feb 17, 2023

Fix wrong code for switch stmt

const int a = 0;

void f() 
{ 
    switch(a)
    {
    default:
    break;
    case 0:
        break;
    }
}
C to V translator 0.3.1
  translating tests/0.switch.c ... tests/0.switch.v:11:2: error: invalid expression: unexpected token `}`
    9 | fn f()  {
   10 |     match a {
   11 |     }
      |     ^
   12 |      else {
   13 |

@felipensp felipensp changed the title fix switch with default before case fix switch with default stmt before case stmt Feb 17, 2023
@ArtemkaKun
Copy link
Contributor

@felipensp I don't think #45 is related to this. The issue says that "can't translate switch if default branch has no break keyword"

@felipensp
Copy link
Member Author

@felipensp I don't think #45 is related to this. The issue says that "can't translate switch if default branch has no break keyword"

hmmm, ok. I just noticed that c2v was generating wrong code with:

const int a = 0;

void f() 
{ 
    switch(a)
    {
    default:
    break;
    case 0:
        break;
    }
}

translating tests/0.switch.c ... tests/0.switch.v:11:2: error: invalid expression: unexpected token `}` 9 | fn main() { 10 | match a { 11 | } | ^ 12 | else { 13 | C.printf(c'foo\n')

@felipensp
Copy link
Member Author

@felipensp I don't think #45 is related to this. The issue says that "can't translate switch if default branch has no break keyword"

hmmm, ok. I just noticed that c2v was generating wrong code with:

const int a = 0;

void f() 
{ 
    switch(a)
    {
    default:
    break;
    case 0:
        break;
    }
}

translating tests/0.switch.c ... tests/0.switch.v:11:2: error: invalid expression: unexpected token `}` 9 | fn main() { 10 | match a { 11 | } | ^ 12 | else { 13 | C.printf(c'foo\n')

I'll treat the #45 in another PR

@ArtemkaKun ArtemkaKun merged commit 2ff3ed6 into master Feb 17, 2023
@felipensp felipensp deleted the fix_switch branch February 17, 2023 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants