File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -11197,7 +11197,9 @@ const ParamTypeIterator = struct {
11197
11197
.Unspecified, .Inline => {
11198
11198
it.zig_index += 1;
11199
11199
it.llvm_index += 1;
11200
- if (ty.isSlice(mod) or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(mod).isSlice(mod))) {
11200
+ if (ty.isSlice(mod) or
11201
+ (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(mod).isSlice(mod) and !ty.ptrAllowsZero(mod)))
11202
+ {
11201
11203
it.llvm_index += 1;
11202
11204
return .slice;
11203
11205
} else if (isByRef(ty, mod)) {
Original file line number Diff line number Diff line change @@ -448,6 +448,23 @@ test "Optional slice size is optimized" {
448
448
try expectEqualStrings (a .? , "hello" );
449
449
}
450
450
451
+ test "Optional slice passed to function" {
452
+ if (builtin .zig_backend == .stage2_aarch64 ) return error .SkipZigTest ; // TODO
453
+ if (builtin .zig_backend == .stage2_arm ) return error .SkipZigTest ; // TODO
454
+ if (builtin .zig_backend == .stage2_sparc64 ) return error .SkipZigTest ; // TODO
455
+
456
+ const S = struct {
457
+ fn foo (a : ? []const u8 ) ! void {
458
+ try std .testing .expectEqualStrings (a .? , "foo" );
459
+ }
460
+ fn bar (a : ? []allowzero const u8 ) ! void {
461
+ try std .testing .expectEqualStrings (@ptrCast (a .? ), "bar" );
462
+ }
463
+ };
464
+ try S .foo ("foo" );
465
+ try S .bar ("bar" );
466
+ }
467
+
451
468
test "peer type resolution in nested if expressions" {
452
469
if (builtin .zig_backend == .stage2_aarch64 ) return error .SkipZigTest ;
453
470
if (builtin .zig_backend == .stage2_arm ) return error .SkipZigTest ;
You can’t perform that action at this time.
0 commit comments