| author | |
| committer | |
| log | 3b60a6de2fd68d7d02de7a10b8b88c919aa088f0 |
| tree | 4dd4233eaf364efec301663c3383501d0afaaf2a |
| parent | c95a34b68f6075d7a9d305d17a6b03bc9fd1fff2 |
Closes #13210
Follow up to 3ccd4907fbcd04ecddffb618a4b14581fd0802792 files changed, 31 insertions(+), 1 deletions(-)
src/Sema.zig+7-1| ... | ... | @@ -6433,7 +6433,7 @@ fn analyzeInlineCallArg( |
| 6433 | 6433 | .ty = param_ty, |
| 6434 | 6434 | .val = arg_val, |
| 6435 | 6435 | }; |
| 6436 | } else if ((try sema.resolveMaybeUndefVal(arg_block, arg_src, casted_arg) == null) or | |
| 6436 | } else if (((try sema.resolveMaybeUndefVal(arg_block, arg_src, casted_arg)) == null) or | |
| 6437 | 6437 | try sema.typeRequiresComptime(param_ty) or zir_tags[inst] == .param_comptime) |
| 6438 | 6438 | { |
| 6439 | 6439 | try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg); |
| ... | ... | @@ -14521,6 +14521,12 @@ fn zirClosureGet( |
| 14521 | 14521 | return sema.failWithOwnedErrorMsg(msg); |
| 14522 | 14522 | } |
| 14523 | 14523 | |
| 14524 | if (tv.val.tag() == .unreachable_value) { | |
| 14525 | assert(block.is_typeof); | |
| 14526 | // We need a dummy runtime instruction with the correct type. | |
| 14527 | return block.addTy(.alloc, tv.ty); | |
| 14528 | } | |
| 14529 | ||
| 14524 | 14530 | return sema.addConstant(tv.ty, tv.val); |
| 14525 | 14531 | } |
| 14526 | 14532 |
test/behavior/sizeof_and_typeof.zig+24| ... | ... | @@ -314,3 +314,27 @@ test "lazy size cast to float" { |
| 314 | 314 | test "bitSizeOf comptime_int" { |
| 315 | 315 | try expect(@bitSizeOf(comptime_int) == 0); |
| 316 | 316 | } |
| 317 | ||
| 318 | test "runtime instructions inside typeof in comptime only scope" { | |
| 319 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 320 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | |
| 321 | ||
| 322 | { | |
| 323 | var y: i8 = 2; | |
| 324 | const i: [2]i8 = [_]i8{ 1, y }; | |
| 325 | const T = struct { | |
| 326 | a: @TypeOf(i) = undefined, // causes crash | |
| 327 | b: @TypeOf(i[0]) = undefined, // causes crash | |
| 328 | }; | |
| 329 | try expect(@TypeOf((T{}).a) == [2]i8); | |
| 330 | try expect(@TypeOf((T{}).b) == i8); | |
| 331 | } | |
| 332 | { | |
| 333 | var y: i8 = 2; | |
| 334 | const i = .{ 1, y }; | |
| 335 | const T = struct { | |
| 336 | b: @TypeOf(i[1]) = undefined, | |
| 337 | }; | |
| 338 | try expect(@TypeOf((T{}).b) == i8); | |
| 339 | } | |
| 340 | } |