mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Crash when trying to convert a struct slice to a vector #2039.
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
- Atomic max was incorrect.
|
||||
- `"+".to_float()` would panic.
|
||||
- `import` can now both be @public and @norecurse.
|
||||
- Crash when trying to convert a struct slice to a vector #2039.
|
||||
|
||||
### Stdlib changes
|
||||
- `new_*` functions in general moved to version without `new_` prefix.
|
||||
|
||||
@@ -1045,16 +1045,21 @@ static bool rule_slice_to_vecarr(CastContext *cc, bool is_explicit, bool is_sile
|
||||
if (is_silent) return false;
|
||||
RETURN_CAST_ERROR(expr, "Zero sized slices can't be converted to arrays or vectors.");
|
||||
}
|
||||
Type *base = cc->from->array.base;
|
||||
if (cc->to_group == CONV_ARRAY)
|
||||
{
|
||||
if (expr_is_const_string(expr) || expr_is_const_bytes(expr))
|
||||
{
|
||||
if (cc->to->array.len > size) size = cc->to->array.len;
|
||||
}
|
||||
cast_context_set_from(cc, type_get_array(cc->from->array.base, size));
|
||||
cast_context_set_from(cc, type_get_array(base, size));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!type_is_valid_for_vector(base))
|
||||
{
|
||||
return report_cast_error(cc, false);
|
||||
}
|
||||
cast_context_set_from(cc, type_get_vector(cc->from->array.base, size));
|
||||
}
|
||||
return cast_is_allowed(cc, is_explicit, is_silent);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Repro issue #2039
|
||||
module foo;
|
||||
struct Foo { void* x; }
|
||||
fn void main()
|
||||
{
|
||||
Foo* foo;
|
||||
float[<2>] a = foo[0..1]; // #error: It is not possible to cast
|
||||
}
|
||||
Reference in New Issue
Block a user