| ... | @@ -1968,44 +1968,38 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1968,44 +1968,38 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1968 | | 1968 | |
| 1969 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 1969 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 1970 | const src = inst_data.src(); | 1970 | const src = inst_data.src(); |
| 1971 | const array = sema.resolveInst(inst_data.operand); | 1971 | const object = sema.resolveInst(inst_data.operand); |
| 1972 | const array_ty = sema.typeOf(array); | 1972 | const object_ty = sema.typeOf(object); |
| 1973 | | 1973 | |
| 1974 | if (array_ty.isSlice()) { | 1974 | const is_pointer_to = object_ty.isSinglePointer(); |
| 1975 | return sema.analyzeSliceLen(block, src, array); | | |
| 1976 | } | | |
| 1977 | | 1975 | |
| 1978 | if (array_ty.isSinglePointer()) { | 1976 | const array_ty = if (is_pointer_to) |
| 1979 | const elem_ty = array_ty.elemType(); | 1977 | object_ty.childType() |
| 1980 | if (elem_ty.isSlice()) { | 1978 | else |
| 1981 | const slice_inst = try sema.analyzeLoad(block, src, array, src); | 1979 | object_ty; |
| 1982 | return sema.analyzeSliceLen(block, src, slice_inst); | 1980 | |
| 1983 | } | 1981 | if (!array_ty.isIndexable()) { |
| 1984 | if (!elem_ty.isIndexable()) { | 1982 | const msg = msg: { |
| 1985 | const msg = msg: { | 1983 | const msg = try sema.errMsg( |
| 1986 | const msg = try sema.errMsg( | 1984 | block, |
| 1987 | block, | 1985 | src, |
| 1988 | src, | 1986 | "type '{}' does not support indexing", |
| 1989 | "type '{}' does not support indexing", | 1987 | .{array_ty}, |
| 1990 | .{elem_ty}, | 1988 | ); |
| 1991 | ); | 1989 | errdefer msg.destroy(sema.gpa); |
| 1992 | errdefer msg.destroy(sema.gpa); | 1990 | try sema.errNote( |
| 1993 | try sema.errNote( | 1991 | block, |
| 1994 | block, | 1992 | src, |
| 1995 | src, | 1993 | msg, |
| 1996 | msg, | 1994 | "for loop operand must be an array, slice, tuple, or vector", |
| 1997 | "for loop operand must be an array, slice, tuple, or vector", | 1995 | .{}, |
| 1998 | .{}, | 1996 | ); |
| 1999 | ); | 1997 | break :msg msg; |
| 2000 | break :msg msg; | 1998 | }; |
| 2001 | }; | 1999 | return sema.failWithOwnedErrorMsg(msg); |
| 2002 | return sema.failWithOwnedErrorMsg(msg); | | |
| 2003 | } | | |
| 2004 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); | | |
| 2005 | return sema.analyzeLoad(block, src, result_ptr, src); | | |
| 2006 | } | 2000 | } |
| 2007 | | 2001 | |
| 2008 | return sema.fail(block, src, "TODO implement Sema.zirIndexablePtrLen", .{}); | 2002 | return sema.fieldVal(block, src, object, "len", src); |
| 2009 | } | 2003 | } |
| 2010 | | 2004 | |
| 2011 | fn zirAllocExtended( | 2005 | fn zirAllocExtended( |
| ... | @@ -10847,7 +10841,7 @@ fn fieldVal( | ... | @@ -10847,7 +10841,7 @@ fn fieldVal( |
| 10847 | }, | 10841 | }, |
| 10848 | else => {}, | 10842 | else => {}, |
| 10849 | } | 10843 | } |
| 10850 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty}); | 10844 | return sema.fail(block, src, "type '{}' does not support field access (fieldVal, {}.{s})", .{object_ty, object_ty, field_name}); |
| 10851 | } | 10845 | } |
| 10852 | | 10846 | |
| 10853 | fn fieldPtr( | 10847 | fn fieldPtr( |
| ... | @@ -11058,7 +11052,7 @@ fn fieldPtr( | ... | @@ -11058,7 +11052,7 @@ fn fieldPtr( |
| 11058 | }, | 11052 | }, |
| 11059 | else => {}, | 11053 | else => {}, |
| 11060 | } | 11054 | } |
| 11061 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty}); | 11055 | return sema.fail(block, src, "type '{}' does not support field access (fieldPtr, {}.{s})", .{object_ty, object_ptr_ty, field_name}); |
| 11062 | } | 11056 | } |
| 11063 | | 11057 | |
| 11064 | fn fieldCallBind( | 11058 | fn fieldCallBind( |