From b7f1dae16f776b8ee9654adc91789fd2497ae69d Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 11 Mar 2023 08:11:03 -0600 Subject: [PATCH] bugfix: special cases in unify_node_and_type --- compiler/src/astnodes.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/src/astnodes.c b/compiler/src/astnodes.c index bc19dce7..3776e08e 100644 --- a/compiler/src/astnodes.c +++ b/compiler/src/astnodes.c @@ -756,18 +756,24 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { // implicitly. This makes working with optionals barable. if (type_struct_constructed_from_poly_struct(type, builtin_optional_type)) { TypeMatch match = unify_node_and_type_(pnode, type->Struct.poly_sln[0].type, permanent); - if (match == TYPE_MATCH_SUCCESS && permanent) { - AstStructLiteral *opt_lit = make_optional_literal_some(context.ast_alloc, node, type); + if (match == TYPE_MATCH_SUCCESS) { + if (permanent) { + AstStructLiteral *opt_lit = make_optional_literal_some(context.ast_alloc, node, type); + + *(AstStructLiteral **) pnode = opt_lit; + } - *(AstStructLiteral **) pnode = opt_lit; return TYPE_MATCH_SUCCESS; } + + if (match == TYPE_MATCH_YIELD) return TYPE_MATCH_YIELD; } // If the node is a numeric literal, try to convert it to the destination type. if (node->kind == Ast_Kind_NumLit) { if (convert_numlit_to_type((AstNumLit *) node, type)) return TYPE_MATCH_SUCCESS; + return TYPE_MATCH_FAILED; } // If the node is a compound expression, and it doesn't have a type created, -- 2.25.1