| ... | @@ -2228,8 +2228,19 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T | ... | @@ -2228,8 +2228,19 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T |
| 2228 | }); | 2228 | }); |
| 2229 | } | 2229 | } |
| 2230 | | 2230 | |
| 2231 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, optional_ty: Type) CompileError { | 2231 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { |
| 2232 | return sema.fail(block, src, "expected optional type, found '{}'", .{optional_ty.fmt(sema.mod)}); | 2232 | const mod = sema.mod; |
| | 2233 | const msg = msg: { |
| | 2234 | const msg = try sema.errMsg(block, src, "expected optional type, found '{}'", .{ |
| | 2235 | non_optional_ty.fmt(mod), |
| | 2236 | }); |
| | 2237 | errdefer msg.destroy(sema.gpa); |
| | 2238 | if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) { |
| | 2239 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| | 2240 | } |
| | 2241 | break :msg msg; |
| | 2242 | }; |
| | 2243 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2233 | } | 2244 | } |
| 2234 | | 2245 | |
| 2235 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { | 2246 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| ... | @@ -9038,7 +9049,7 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -9038,7 +9049,7 @@ fn analyzeOptionalPayloadPtr( |
| 9038 | | 9049 | |
| 9039 | const opt_type = optional_ptr_ty.childType(zcu); | 9050 | const opt_type = optional_ptr_ty.childType(zcu); |
| 9040 | if (opt_type.zigTypeTag(zcu) != .Optional) { | 9051 | if (opt_type.zigTypeTag(zcu) != .Optional) { |
| 9041 | return sema.fail(block, src, "expected optional type, found '{}'", .{opt_type.fmt(zcu)}); | 9052 | return sema.failWithExpectedOptionalType(block, src, opt_type); |
| 9042 | } | 9053 | } |
| 9043 | | 9054 | |
| 9044 | const child_type = opt_type.optionalChild(zcu); | 9055 | const child_type = opt_type.optionalChild(zcu); |