Core: More robust '.' access

This commit is contained in:
Krzosa Karol
2023-04-21 15:09:07 +02:00
parent 32cda2b59e
commit 19fa0509c6
2 changed files with 3 additions and 24 deletions

View File

@@ -1,6 +1,3 @@
/*@language_refactor: Remove tuples and simplify, Make var unpacking general*/ /*@language_refactor: Remove tuples and simplify, Make var unpacking general*/
/*@language_todo: make polymorphism checking more robust*/ /*@language_todo: make polymorphism checking more robust*/
@@ -25,24 +22,6 @@ thing := 1
:goto_block: for :goto_block: for
@reproduction:
This kills the compiler due to referencing slice data
Array :: struct($T: Type)
slice: []T
cap: S64
Guy :: struct
pos: Vector2
Add :: (a: *Array($T), item: T)
if a.cap == 0
a.cap = 16
a.slice.data = malloc(sizeof(T) * a.cap)
a.slice.data[a.slice.len++] = item
guys: Array(Guy)
Add(&guys, {100, 100})
*/ */
#import "raylib.core" #import "raylib.core"

View File

@@ -1344,9 +1344,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
if (is_pointer(type)) type = type->base; if (is_pointer(type)) type = type->base;
type_complete(type); type_complete(type);
if (!type->ast) { bool is_dottable_type = type->kind == TYPE_STRUCT || type->kind == TYPE_UNION;
compiler_error(node->pos, "Builtin type %Q doesn't have anything to access using '.' operator", typestring(type)); if (is_dottable_type == false) compiler_error(node->pos, "Type %Q doesn't have anything to access using '.' operator", typestring(type));
}
scope = ((Ast_Decl *)type->ast)->scope; scope = ((Ast_Decl *)type->ast)->scope;
if (!scope) { if (!scope) {
compiler_error(node->pos, "Internal compiler error? Type %Q doesn't have scope, you cannot use '.' on this variable", typestring(type)); compiler_error(node->pos, "Internal compiler error? Type %Q doesn't have scope, you cannot use '.' on this variable", typestring(type));