diff --git a/lib/std/std.sunder b/lib/std/std.sunder index cac76e67..7b2915dd 100644 --- a/lib/std/std.sunder +++ b/lib/std/std.sunder @@ -19,13 +19,16 @@ struct error_info { # in the value state, indicating computation success, or the error state, # indicating computation failure. struct result[[T, E]] { - var _data: _result_union[[T, E]]; + var _data: union { + var value: T; + var error: E; + }; var _is_value: bool; # Initialize a result in the value state (success). func init_value(value: T) result[[T, E]] { return (:result[[T, E]]){ - ._data = (:_result_union[[T, E]]){._value = value}, + ._data = (:union { var value: T; var error: E; }){.value = value}, ._is_value = true, }; } @@ -33,7 +36,7 @@ struct result[[T, E]] { # Initialize a result in the error state (failure). func init_error(error: E) result[[T, E]] { return (:result[[T, E]]){ - ._data = (:_result_union[[T, E]]){._error = error}, + ._data = (:union { var value: T; var error: E; }){.error = error}, ._is_value = false, }; } @@ -55,7 +58,7 @@ struct result[[T, E]] { if not self.*._is_value { std::panic("attempted to retrieve value from std::result in the error state"); } - return self.*._data._value; + return self.*._data.value; } # Returns the error associated with a result in the error state. @@ -65,15 +68,10 @@ struct result[[T, E]] { if self.*._is_value { std::panic("attempted to retrieve error from std::result in the value state"); } - return self.*._data._error; + return self.*._data.error; } } -union _result_union[[T, E]] { - var _value: T; - var _error: E; -} - # Type representing a value that may not be present. An optional is either in # the value state, indicating that the value is present, or the empty state, # indicating that the value is absent. diff --git a/resolve.c b/resolve.c index 1c93e6a3..8cbc3d8e 100644 --- a/resolve.c +++ b/resolve.c @@ -5559,7 +5559,7 @@ resolve_type_struct(struct resolver* resolver, struct cst_type const* type) } struct symbol_table* const struct_symbols = - symbol_table_new(context()->global_symbol_table); + symbol_table_new(resolver->current_symbol_table); sbuf_push(context()->chilling_symbol_tables, struct_symbols); struct type* const resolved_type = type_new_struct(name, struct_symbols); freeze(resolved_type); @@ -5624,7 +5624,7 @@ resolve_type_union(struct resolver* resolver, struct cst_type const* type) } struct symbol_table* const union_symbols = - symbol_table_new(context()->global_symbol_table); + symbol_table_new(resolver->current_symbol_table); sbuf_push(context()->chilling_symbol_tables, union_symbols); struct type* const resolved_type = type_new_union(name, union_symbols); freeze(resolved_type);