mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-12 06:18:39 +00:00
Merge pull request #6110 from ske2004/fix-constant-conversion-checks
Fix constant conversion checks (#6104)
This commit is contained in:
@@ -3526,28 +3526,17 @@ gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type)
|
||||
Type *elem = core_array_type(bt);
|
||||
|
||||
if (core_type(bt)->kind == Type_Basic) {
|
||||
if (check_representable_as_constant(c, x->value, type, &x->value)) {
|
||||
return true;
|
||||
}
|
||||
goto check_castable;
|
||||
} else if (!are_types_identical(elem, bt) &&
|
||||
elem->kind == Type_Basic &&
|
||||
check_representable_as_constant(c, x->value, elem, &x->value)) {
|
||||
if (check_representable_as_constant(c, x->value, type, &x->value)) {
|
||||
return true;
|
||||
}
|
||||
goto check_castable;
|
||||
return check_representable_as_constant(c, x->value, type, &x->value) ||
|
||||
(is_type_pointer(type) && check_is_castable_to(c, x, type));
|
||||
} else if (!are_types_identical(elem, bt) && elem->kind == Type_Basic) {
|
||||
return check_representable_as_constant(c, x->value, elem, &x->value) ||
|
||||
(is_type_pointer(elem) && check_is_castable_to(c, x, elem));
|
||||
} else if (check_is_castable_to(c, x, type)) {
|
||||
x->value = {};
|
||||
x->mode = Addressing_Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
check_castable:
|
||||
if (check_is_castable_to(c, x, type)) {
|
||||
} else if (check_is_castable_to(c, x, type)) {
|
||||
if (x->mode != Addressing_Constant) {
|
||||
x->mode = Addressing_Value;
|
||||
} else if (is_type_slice(type) && is_type_string(x->type)) {
|
||||
|
||||
@@ -58,14 +58,14 @@ test_issue_6068 :: proc(t: ^testing.T) {
|
||||
testing.expect(t, f64be(-1.234) == check_be)
|
||||
testing.expect(t, cast(f64be)value == check_be)
|
||||
testing.expect(t, cast(f64be)-1.234 == check_be)
|
||||
testing.expect(t, f64be(int(-1.234)) == check_be)
|
||||
testing.expect(t, cast(f64be)int(-1.234) == check_be)
|
||||
testing.expect(t, f64be(f64(-1.234)) == check_be)
|
||||
testing.expect(t, cast(f64be)f64(-1.234) == check_be)
|
||||
testing.expect(t, f64le(value) == check_le)
|
||||
testing.expect(t, f64le(-1.234) == check_le)
|
||||
testing.expect(t, cast(f64le)value == check_le)
|
||||
testing.expect(t, cast(f64le)-1.234 == check_le)
|
||||
testing.expect(t, f64le(int(-1.234)) == check_le)
|
||||
testing.expect(t, cast(f64le)int(-1.234) == check_le)
|
||||
testing.expect(t, f64le(f64(-1.234)) == check_le)
|
||||
testing.expect(t, cast(f64le)f64(-1.234) == check_le)
|
||||
testing.expect(t, f64le(reverse) == check_le)
|
||||
testing.expect(t, cast(f64le)reverse == check_le)
|
||||
|
||||
@@ -74,14 +74,14 @@ test_issue_6068 :: proc(t: ^testing.T) {
|
||||
testing.expect(t, f64be(-1.234) == -1.234)
|
||||
testing.expect(t, cast(f64be)value == -1.234)
|
||||
testing.expect(t, cast(f64be)-1.234 == -1.234)
|
||||
testing.expect(t, f64be(int(-1.234)) == -1.234)
|
||||
testing.expect(t, cast(f64be)int(-1.234) == -1.234)
|
||||
testing.expect(t, f64be(f64(-1.234)) == -1.234)
|
||||
testing.expect(t, cast(f64be)f64(-1.234) == -1.234)
|
||||
testing.expect(t, f64le(value) == -1.234)
|
||||
testing.expect(t, f64le(-1.234) == -1.234)
|
||||
testing.expect(t, cast(f64le)value == -1.234)
|
||||
testing.expect(t, cast(f64le)-1.234 == -1.234)
|
||||
testing.expect(t, f64le(int(-1.234)) == -1.234)
|
||||
testing.expect(t, cast(f64le)int(-1.234) == -1.234)
|
||||
testing.expect(t, f64le(f64(-1.234)) == -1.234)
|
||||
testing.expect(t, cast(f64le)f64(-1.234) == -1.234)
|
||||
testing.expect(t, f64le(reverse) == -1.234)
|
||||
testing.expect(t, cast(f64le)reverse == -1.234)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user