diff options
| author | gingerBill <bill@gingerbill.org> | 2023-07-07 22:56:20 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-07-07 22:56:20 +0100 |
| commit | 3758be55f562cadae17845bfdda1df0431b2a5df (patch) | |
| tree | 7b2efb54ef091d698e92dc2d8c9ed76c839db7f7 /src/check_expr.cpp | |
| parent | 8f4c59b0801cc5ffa9ea10f72c29a94245f0bbb1 (diff) | |
Fix #2630
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 7b3ddfc73..77c351cce 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -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 (is_type_typed(dst) && src->kind == Type_Basic) { switch (src->Basic.kind) { + case Basic_UntypedBool: + if (is_type_boolean(dst)) { + return 1; + } + break; case Basic_UntypedRune: if (is_type_integer(dst) || is_type_rune(dst)) { return 1; @@ -704,46 +709,55 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand return -1; } if (src->kind == Type_Basic) { + Type *d = base_array_type(dst); i64 score = -1; switch (src->Basic.kind) { + case Basic_UntypedBool: + if (is_type_boolean(d)) { + score = 1; + } + break; case Basic_UntypedRune: - if (is_type_integer(dst) || is_type_rune(dst)) { + if (is_type_integer(d) || is_type_rune(d)) { score = 1; } break; case Basic_UntypedInteger: - if (is_type_integer(dst) || is_type_rune(dst)) { + if (is_type_integer(d) || is_type_rune(d)) { score = 1; } break; case Basic_UntypedString: - if (is_type_string(dst)) { + if (is_type_string(d)) { score = 1; } break; case Basic_UntypedFloat: - if (is_type_float(dst)) { + if (is_type_float(d)) { score = 1; } break; case Basic_UntypedComplex: - if (is_type_complex(dst)) { + if (is_type_complex(d)) { score = 1; } - if (is_type_quaternion(dst)) { + if (is_type_quaternion(d)) { score = 2; } break; case Basic_UntypedQuaternion: - if (is_type_quaternion(dst)) { + if (is_type_quaternion(d)) { score = 1; } break; } if (score > 0) { - if (is_type_typed(dst)) { + if (is_type_typed(d)) { score += 1; } + if (d != dst) { + score += 6; + } } return score; } |