Allow opaque to be polymorphic

This commit is contained in:
gingerBill
2018-11-17 10:08:06 +00:00
parent 3061bc8478
commit f61c4715c1
2 changed files with 12 additions and 1 deletions

View File

@@ -803,6 +803,11 @@ bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source,
}
return true;
}
case Type_Opaque:
if (source->kind == Type_Opaque) {
return is_polymorphic_type_assignable(c, poly->Opaque.elem, source->Opaque.elem, true, modify_type);
}
return false;
case Type_Pointer:
if (source->kind == Type_Pointer) {
return is_polymorphic_type_assignable(c, poly->Pointer.elem, source->Pointer.elem, true, modify_type);

View File

@@ -1127,7 +1127,8 @@ bool is_type_polymorphic(Type *t) {
case Type_Named:
return is_type_polymorphic(t->Named.base);
case Type_Opaque:
return is_type_polymorphic(t->Opaque.elem);
case Type_Pointer:
return is_type_polymorphic(t->Pointer.elem);
case Type_Array:
@@ -2571,6 +2572,11 @@ gbString write_type_to_string(gbString str, Type *type) {
str = write_type_to_string(str, type->Pointer.elem);
break;
case Type_Opaque:
str = gb_string_appendc(str, "opaque ");
str = write_type_to_string(str, type->Opaque.elem);
break;
case Type_Array:
str = gb_string_appendc(str, gb_bprintf("[%d]", cast(int)type->Array.count));
str = write_type_to_string(str, type->Array.elem);