From: Brendan Hansen Date: Sun, 24 Jan 2021 05:56:07 +0000 (-0600) Subject: small bugfixes with error message production X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=cc7a27da36422422d92fc677607c1fbf9762d80a;p=onyx.git small bugfixes with error message production --- diff --git a/bin/onyx b/bin/onyx index f4d0eb56..74d7969d 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/onyx.exe b/onyx.exe index c8e01198..6949f75b 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxastnodes.c b/src/onyxastnodes.c index 1518a750..1ea640df 100644 --- a/src/onyxastnodes.c +++ b/src/onyxastnodes.c @@ -28,7 +28,7 @@ static const char* ast_node_names[] = { "BIN_OP", "COMPOUND", - "NAMED_VALUE" + "NAMED_VALUE", "TYPE_START (BAD)", "TYPE", diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 4024070c..8b4d61e5 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -695,12 +695,30 @@ void symres_function_header(AstFunction* func) { scope_enter(func->scope); bh_arr_each(AstParam, param, func->params) { + symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local); + + // CLEANUP: Currently, in order to 'use' parameters, the type must be completely + // resolved and built. This is excessive because all that should need to be known + // is the names of the members, since all that happens is implicit field accesses + // are placed in the scope. So instead, there should be a way to just query all the + // member names in the structure, without needing to know their type. This would be + // easy if it were not for 'use' statements in structs. It is made even more complicated + // by this situtation: + // + // Foo :: struct (T: type_expr) { + // use t : T; + // + // something_else := 5 + 6 * 8; + // } + // + // The 'use t : T' member requires completely knowing the type of T, to know which + // members should be brought in. At the moment, that requires completely building the + // type of Foo($T), which is not possible, because the defaulted member 'something_else' + // does not have a known type until the default memory gets checked and reduced. if (param->local->type_node != NULL) { param->local->type_node = symres_type(param->local->type_node); } - symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local); - if (param->local->flags & Ast_Flag_Param_Use) { if (param->local->type_node != NULL && param->local->type == NULL) { param->local->type = type_build_from_ast(context.ast_alloc, param->local->type_node); diff --git a/src/onyxtypes.c b/src/onyxtypes.c index 6b304ed0..eefe755c 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -530,6 +530,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { // CLEANUP: Maybe don't copy it and just use this one since it is allocated on the heap? bh_arr_free(slns); + if (!concrete) return NULL; return type_build_from_ast(alloc, (AstType *) concrete); } diff --git a/src/onyxutils.c b/src/onyxutils.c index 8dd71292..a8a3a65f 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -955,7 +955,6 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP insert_poly_slns_into_scope(ps_type->scope, slns); AstStructType* concrete_struct = (AstStructType *) ast_clone(context.ast_alloc, ps_type->base_struct); - bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct); Entity struct_entity = { .state = Entity_State_Resolve_Symbols, @@ -977,9 +976,12 @@ AstStructType* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstP if (onyx_has_errors()) { onyx_report_error(pos, "Error in creating polymoprhic struct instantiation here."); + bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, NULL); return NULL; } + bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct); + Type* cs_type = type_build_from_ast(context.ast_alloc, (AstType *) concrete_struct); cs_type->Struct.poly_sln = NULL; bh_arr_new(global_heap_allocator, cs_type->Struct.poly_sln, bh_arr_length(slns));