Commit 9a358d2d33

Jonathan Marler <jonathan.j.marler@hp.com>
2019-09-04 19:08:49
Add Array support to @Type
1 parent 847a262
Changed files (2)
src
test
stage1
behavior
src/ir.cpp
@@ -20942,6 +20942,13 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
                     return ptr_type;
                 return get_slice_type(ira->codegen, ptr_type);
             }
+        case ZigTypeIdArray:
+            assert(payload->special == ConstValSpecialStatic);
+            assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
+            return get_array_type(ira->codegen,
+                get_const_field_meta_type(ira, payload, "child", 1),
+                bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0))
+            );
         case ZigTypeIdComptimeFloat:
             return ira->codegen->builtin_types.entry_num_lit_float;
         case ZigTypeIdComptimeInt:
@@ -20950,7 +20957,6 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
             return ira->codegen->builtin_types.entry_undef;
         case ZigTypeIdNull:
             return ira->codegen->builtin_types.entry_null;
-        case ZigTypeIdArray:
         case ZigTypeIdOptional:
         case ZigTypeIdErrorUnion:
         case ZigTypeIdErrorSet:
test/stage1/behavior/type.zig
@@ -93,6 +93,12 @@ test "Type.Pointer" {
     });
 }
 
+test "Type.Array" {
+    testing.expect([123]u8 == @Type(TypeInfo { .Array = TypeInfo.Array { .len = 123, .child = u8 } }));
+    testing.expect([2]u32 == @Type(TypeInfo { .Array = TypeInfo.Array { .len = 2, .child = u32 } }));
+    testTypes([_]type {[1]u8, [30]usize, [7]bool});
+}
+
 test "Type.ComptimeFloat" {
     testTypes([_]type {comptime_float});
 }