Skip to content

stage1 and stage2: closes #7120 #7122

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

Closed
wants to merge 2 commits into from
Closed

stage1 and stage2: closes #7120 #7122

wants to merge 2 commits into from

Conversation

g-w1
Copy link
Contributor

@g-w1 g-w1 commented Nov 16, 2020

This fixes a case where

pub fn main() {
  const x = error.T;
  switch (x) {
    error.T => {},
    else => {},
  }
}

was allowed. Funnily, the stdlib and some parts of stage2 included this pattern, so I fixed it there too.
My editor does weird stuff with whitespace, so feel free to ignore that.
See here for conversation on irc.

@alexnask alexnask added the stage1 The process of building from source via WebAssembly and the C backend. label Nov 16, 2020
Copy link
Contributor

@LemonBoy LemonBoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The stage2 part is missing?
  • This needs a compile-error test
  • The commit messages are really bad, have a look here for inspiration

@@ -29544,6 +29544,23 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
}
}
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
} else if (!type_is_global_error_set(switch_type)) {

You can save a whole indentation level.

} else {
if (!type_is_global_error_set(switch_type)) {
bool needs_else = false;
for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a more expensive version of const bool needs_else = instruction->range_count != switch_type->data.error_set.err_count ?
By the time you reach this line the compiler already knows all the values are correctly typed and the prong list contains no duplicates.


AstNode *prev_node = field_prev_uses[err_entry->value];
if (prev_node == nullptr) {
needs_else = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, the indentation is off and you can exit with a break once this becomes true.

@g-w1
Copy link
Contributor Author

g-w1 commented Nov 16, 2020

Thanks. I think I am going to close this pr as #5693 is already trying to handle it and also vexu said that it was intentional #7120 (comment).

@g-w1 g-w1 closed this Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants