Skip to content

implement #1107 - #2799

Merged
andrewrk merged 2 commits into
ziglang:masterfrom
emekoi:impl-1107
Jul 4, 2019
Merged

implement #1107#2799
andrewrk merged 2 commits into
ziglang:masterfrom
emekoi:impl-1107

Conversation

@emekoi

Copy link
Copy Markdown
Contributor

this closes#1107.

added error for switch prong with different payloads and support for capturing payload on switch prongs with payloads of the same type
@emekoi

emekoi commented Jul 1, 2019

Copy link
Copy Markdown
ContributorAuthor

this would introduce an error for capture groups on else prongs for tagged unions, but i'm not sure if that is desirable beahvior.

diff --git a/src/ir.cpp b/src/ir.cpp
index d4cb5f90..ad788e9f 100644
--- a/src/ir.cpp+++ b/src/ir.cpp@@ -19311,6 +19311,9 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
ref_type->data.pointer.allow_zero);
return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,
&instruction->base, false);
+ } else if (target_type->id == ZigTypeIdUnion) {+ ir_add_error(ira, &instruction->base, buf_create_from_str("capture group not allowed on else prong"));+ return ira->codegen->invalid_instruction;
}
return target_value_ptr;

@emekoi
emekoi marked this pull request as ready for review July 1, 2019 07:34
@andrewrk

Copy link
Copy Markdown
Member

Can you add a new behavioral test?

@andrewrk
andrewrk merged commit a1b952f into ziglang:masterJul 4, 2019
Sign up for freeto 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.

when multiple union fields share the same type, allow them to share a body in a switch prong

2 participants

@emekoi@andrewrk