mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Fix #2630
This commit is contained in:
+22
-8
@@ -664,6 +664,11 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand
|
|||||||
if (check_representable_as_constant(c, operand->value, dst, nullptr)) {
|
if (check_representable_as_constant(c, operand->value, dst, nullptr)) {
|
||||||
if (is_type_typed(dst) && src->kind == Type_Basic) {
|
if (is_type_typed(dst) && src->kind == Type_Basic) {
|
||||||
switch (src->Basic.kind) {
|
switch (src->Basic.kind) {
|
||||||
|
case Basic_UntypedBool:
|
||||||
|
if (is_type_boolean(dst)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Basic_UntypedRune:
|
case Basic_UntypedRune:
|
||||||
if (is_type_integer(dst) || is_type_rune(dst)) {
|
if (is_type_integer(dst) || is_type_rune(dst)) {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -704,46 +709,55 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (src->kind == Type_Basic) {
|
if (src->kind == Type_Basic) {
|
||||||
|
Type *d = base_array_type(dst);
|
||||||
i64 score = -1;
|
i64 score = -1;
|
||||||
switch (src->Basic.kind) {
|
switch (src->Basic.kind) {
|
||||||
|
case Basic_UntypedBool:
|
||||||
|
if (is_type_boolean(d)) {
|
||||||
|
score = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Basic_UntypedRune:
|
case Basic_UntypedRune:
|
||||||
if (is_type_integer(dst) || is_type_rune(dst)) {
|
if (is_type_integer(d) || is_type_rune(d)) {
|
||||||
score = 1;
|
score = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Basic_UntypedInteger:
|
case Basic_UntypedInteger:
|
||||||
if (is_type_integer(dst) || is_type_rune(dst)) {
|
if (is_type_integer(d) || is_type_rune(d)) {
|
||||||
score = 1;
|
score = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Basic_UntypedString:
|
case Basic_UntypedString:
|
||||||
if (is_type_string(dst)) {
|
if (is_type_string(d)) {
|
||||||
score = 1;
|
score = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Basic_UntypedFloat:
|
case Basic_UntypedFloat:
|
||||||
if (is_type_float(dst)) {
|
if (is_type_float(d)) {
|
||||||
score = 1;
|
score = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Basic_UntypedComplex:
|
case Basic_UntypedComplex:
|
||||||
if (is_type_complex(dst)) {
|
if (is_type_complex(d)) {
|
||||||
score = 1;
|
score = 1;
|
||||||
}
|
}
|
||||||
if (is_type_quaternion(dst)) {
|
if (is_type_quaternion(d)) {
|
||||||
score = 2;
|
score = 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Basic_UntypedQuaternion:
|
case Basic_UntypedQuaternion:
|
||||||
if (is_type_quaternion(dst)) {
|
if (is_type_quaternion(d)) {
|
||||||
score = 1;
|
score = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (score > 0) {
|
if (score > 0) {
|
||||||
if (is_type_typed(dst)) {
|
if (is_type_typed(d)) {
|
||||||
score += 1;
|
score += 1;
|
||||||
}
|
}
|
||||||
|
if (d != dst) {
|
||||||
|
score += 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,17 +285,6 @@ gb_internal Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void destroy_scope(Scope *scope) {
|
gb_internal void destroy_scope(Scope *scope) {
|
||||||
for (auto const &entry : scope->elements) {
|
|
||||||
Entity *e = entry.value;
|
|
||||||
if (e->kind == Entity_Variable) {
|
|
||||||
if (!(e->flags & EntityFlag_Used)) {
|
|
||||||
#if 0
|
|
||||||
warning(e->token, "Unused variable '%.*s'", LIT(e->token.string));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Scope *child = scope->head_child; child != nullptr; child = child->next) {
|
for (Scope *child = scope->head_child; child != nullptr; child = child->next) {
|
||||||
destroy_scope(child);
|
destroy_scope(child);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user