diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-05-08 00:59:21 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-05-08 00:59:21 -0700 |
| commit | 18ed87c695398a1fbe972d0f8d212365a9832883 (patch) | |
| tree | a7338cd8326d3ab7876001420884a4723344c3da /src/analyze.cpp | |
| parent | aed96e35126eb6bb6c280f6517f59b5f17d7e61e (diff) | |
| download | zig-18ed87c695398a1fbe972d0f8d212365a9832883.tar.gz zig-18ed87c695398a1fbe972d0f8d212365a9832883.zip | |
ability to cast u8 slice to bigger slice
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 893da7fd5e..133cbf47fa 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4240,17 +4240,16 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B return resolve_cast(g, context, node, expr_node, wanted_type, CastOpToUnknownSizeArray, true); } - // explicit cast from []T to []u8 - if (is_slice(wanted_type) && - is_u8(wanted_type->data.structure.fields[0].type_entry->data.pointer.child_type) && - is_slice(actual_type) && + // explicit cast from []T to []u8 or []u8 to []T + if (is_slice(wanted_type) && is_slice(actual_type) && + (is_u8(wanted_type->data.structure.fields[0].type_entry->data.pointer.child_type) || + is_u8(actual_type->data.structure.fields[0].type_entry->data.pointer.child_type)) && (wanted_type->data.structure.fields[0].type_entry->data.pointer.is_const || !actual_type->data.structure.fields[0].type_entry->data.pointer.is_const)) { return resolve_cast(g, context, node, expr_node, wanted_type, CastOpResizeSlice, true); } - // explicit cast from pointer to another pointer if ((actual_type->id == TypeTableEntryIdPointer || actual_type->id == TypeTableEntryIdFn) && (wanted_type->id == TypeTableEntryIdPointer || wanted_type->id == TypeTableEntryIdFn)) |
