| ... | ... | @@ -908,6 +908,33 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr |
| 908 | 908 | ); |
| 909 | 909 | } |
| 910 | 910 | }, |
| 911 | .Pointer => { |
| 912 | const ptr_child = elem_ty.elemType(); |
| 913 | switch (ptr_child.zigTypeTag()) { |
| 914 | .Array => { |
| 915 | if (mem.eql(u8, field_name, "len")) { |
| 916 | const len_payload = try scope.arena().create(Value.Payload.Int_u64); |
| 917 | len_payload.* = .{ .int = ptr_child.arrayLen() }; |
| 918 | |
| 919 | const ref_payload = try scope.arena().create(Value.Payload.RefVal); |
| 920 | ref_payload.* = .{ .val = Value.initPayload(&len_payload.base) }; |
| 921 | |
| 922 | return mod.constInst(scope, fieldptr.base.src, .{ |
| 923 | .ty = Type.initTag(.single_const_pointer_to_comptime_int), |
| 924 | .val = Value.initPayload(&ref_payload.base), |
| 925 | }); |
| 926 | } else { |
| 927 | return mod.fail( |
| 928 | scope, |
| 929 | fieldptr.positionals.field_name.src, |
| 930 | "no member named '{}' in '{}'", |
| 931 | .{ field_name, elem_ty }, |
| 932 | ); |
| 933 | } |
| 934 | }, |
| 935 | else => {}, |
| 936 | } |
| 937 | }, |
| 911 | 938 | .Type => { |
| 912 | 939 | _ = try mod.resolveConstValue(scope, object_ptr); |
| 913 | 940 | const result = try mod.analyzeDeref(scope, fieldptr.base.src, object_ptr, object_ptr.src); |
| ... | ... | @@ -940,8 +967,9 @@ fn analyzeInstFieldPtr(mod: *Module, scope: *Scope, fieldptr: *zir.Inst.FieldPtr |
| 940 | 967 | else => return mod.fail(scope, fieldptr.base.src, "type '{}' does not support field access", .{child_type}), |
| 941 | 968 | } |
| 942 | 969 | }, |
| 943 | | else => return mod.fail(scope, fieldptr.base.src, "type '{}' does not support field access", .{elem_ty}), |
| 970 | else => {}, |
| 944 | 971 | } |
| 972 | return mod.fail(scope, fieldptr.base.src, "type '{}' does not support field access", .{elem_ty}); |
| 945 | 973 | } |
| 946 | 974 | |
| 947 | 975 | fn analyzeInstIntCast(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) InnerError!*Inst { |