mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-23 22:25:00 -07:00
Fix type aliasing comparison; Fix gb_utf8_decode
This commit is contained in:
@@ -248,16 +248,6 @@ void check_type_decl(CheckerContext *ctx, Entity *e, AstNode *type_expr, Type *d
|
||||
named->Named.base = bt;
|
||||
e->TypeName.is_type_alias = true;
|
||||
}
|
||||
// if (is_alias) {
|
||||
// if (is_type_named(bt)) {
|
||||
// e->type = bt;
|
||||
// e->TypeName.is_type_alias = true;
|
||||
// } else {
|
||||
// gbString str = type_to_string(bt);
|
||||
// error(type_expr, "Type alias declaration with a non-named type '%s'", str);
|
||||
// gb_string_free(str);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-3
@@ -946,8 +946,8 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) {
|
||||
if (switch_kind == TypeSwitch_Union) {
|
||||
GB_ASSERT(is_type_union(bt));
|
||||
bool tag_type_found = false;
|
||||
for_array(i, bt->Union.variants) {
|
||||
Type *vt = bt->Union.variants[i];
|
||||
for_array(j, bt->Union.variants) {
|
||||
Type *vt = bt->Union.variants[j];
|
||||
if (are_types_identical(vt, y.type)) {
|
||||
tag_type_found = true;
|
||||
break;
|
||||
@@ -955,7 +955,11 @@ void check_type_switch_stmt(CheckerContext *ctx, AstNode *node, u32 mod_flags) {
|
||||
}
|
||||
if (!tag_type_found) {
|
||||
gbString type_str = type_to_string(y.type);
|
||||
error(y.expr, "Unknown tag type, got '%s'", type_str);
|
||||
error(y.expr, "Unknown variant type, got '%s'", type_str);
|
||||
for_array(j, bt->Union.variants) {
|
||||
Type *vt = base_type(bt->Union.variants[j]);
|
||||
gb_printf_err("\t%s\n", type_to_string(vt));
|
||||
}
|
||||
gb_string_free(type_str);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -603,6 +603,10 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast
|
||||
enum_type->Enum.is_export = et->is_export;
|
||||
if (et->is_export) {
|
||||
Scope *parent = ctx->scope->parent;
|
||||
if (parent->is_file) {
|
||||
// NOTE(bhall): Use package scope
|
||||
parent = parent->parent;
|
||||
}
|
||||
for_array(i, fields) {
|
||||
Entity *f = fields[i];
|
||||
if (f->kind != Entity_Constant) {
|
||||
|
||||
+1
-1
@@ -6894,7 +6894,7 @@ isize gb_utf8_decode(u8 const *str, isize str_len, Rune *codepoint_out) {
|
||||
u8 x = gb__utf8_first[s0], sz;
|
||||
u8 b1, b2, b3;
|
||||
gbUtf8AcceptRange accept;
|
||||
if (x > 0xf0) {
|
||||
if (x >= 0xf0) {
|
||||
Rune mask = (cast(Rune)x >> 31) << 31;
|
||||
codepoint = (cast(Rune)s0 & (~mask)) | (GB_RUNE_INVALID & mask);
|
||||
width = 1;
|
||||
|
||||
@@ -1157,6 +1157,19 @@ bool is_type_comparable(Type *t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Type *strip_type_aliasing(Type *x) {
|
||||
if (x == nullptr) {
|
||||
return x;
|
||||
}
|
||||
if (x->kind == Type_Named) {
|
||||
Entity *e = x->Named.type_name;
|
||||
if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) {
|
||||
return x->Named.base;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
bool are_types_identical(Type *x, Type *y) {
|
||||
if (x == y) {
|
||||
return true;
|
||||
@@ -1167,6 +1180,9 @@ bool are_types_identical(Type *x, Type *y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
x = strip_type_aliasing(x);
|
||||
y = strip_type_aliasing(y);
|
||||
|
||||
switch (x->kind) {
|
||||
case Type_Generic:
|
||||
if (y->kind == Type_Generic) {
|
||||
|
||||
Reference in New Issue
Block a user