There were too many places were the fact the ZII was not followed for union types was too annoying.
return legal ? TYPE_MATCH_SUCCESS : TYPE_MATCH_FAILED;
}
+ if (node->kind == Ast_Kind_Zero_Value) {
+ if (node_type == NULL) {
+ node->type = type;
+ return TYPE_MATCH_SUCCESS; // Shouldn't this be on the next line? And have node_type == node->type checked?
+ }
+ }
+
+
// If the destination type is an optional, and the node's type is a value of
// the same underlying type, then we can construct an optional with a value
// implicitly. This makes working with optionals barable.
}
}
- if (node->kind == Ast_Kind_Zero_Value) {
- if (node_type == NULL) {
- node->type = type;
- return TYPE_MATCH_SUCCESS; // Shouldn't this be on the next line? And have node_type == node->type checked?
- }
- }
-
//
// This is a SUPER RARE case. It is used when checking to
// see if the return value from a interface constraint is
arguments_initialize(&opt_lit->args);
arguments_ensure_length(&opt_lit->args, 2);
- opt_lit->args.values[0] = (AstTyped *) make_int_literal(a, 2);
+ opt_lit->args.values[0] = (AstTyped *) make_int_literal(a, 1); // 1 is Some
opt_lit->args.values[1] = expr;
opt_lit->type = opt_type;
// We subtract one here because variant numbering starts at 1, instead of 0.
// This is so a zeroed out block of memory does not have a valid variant.
- i32 variant_number = get_expression_integer_value(*value, NULL) - 1;
+ // This is going to change now...
+ i32 variant_number = get_expression_integer_value(*value, NULL);
switchnode->union_variants_handled[variant_number] = 1;
UnionVariant *union_variant = union_expr_type->Union.variants_ordered[variant_number];
u32 size = 0;
u32 alignment = 0;
- u32 next_tag_value = 1;
+ u32 next_tag_value = 0;
AstEnumType* tag_enum_node = onyx_ast_node_new(alloc, sizeof(AstEnumType), Ast_Kind_Enum_Type);
tag_enum_node->token = union_->token;
WI(NULL, WI_I32_EQ);
emit_enter_structured_block(mod, &code, SBT_Basic_If, field->token);
emit_stack_address(mod, &code, intermediate_local, field->token);
- WIL(NULL, WI_I32_CONST, 2); // 2 is Some
+ WIL(NULL, WI_I32_CONST, 1); // 1 is Some
emit_store_instruction(mod, &code, &basic_types[Basic_Kind_I32], 0);
emit_stack_address(mod, &code, intermediate_local + type_alignment_of(field->type), field->token);
WI(NULL, WI_ELSE);
emit_stack_address(mod, &code, intermediate_local, field->token);
- WIL(NULL, WI_I32_CONST, 1); // 1 is None
+ WIL(NULL, WI_I32_CONST, 0); // 0 is None
emit_store_instruction(mod, &code, &basic_types[Basic_Kind_I32], 0);
emit_leave_structured_block(mod, &code);