From 18ed87c695398a1fbe972d0f8d212365a9832883 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 8 May 2016 00:59:21 -0700 Subject: ability to cast u8 slice to bigger slice --- src/analyze.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/analyze.cpp') 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)) -- cgit v1.2.3