File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -3198,7 +3198,8 @@ pub const DeclGen = struct {
3198
3198
/// There are other similar cases handled here as well.
3199
3199
fn lowerPtrElemTy (dg : * DeclGen , elem_ty : Type ) Allocator.Error ! * llvm.Type {
3200
3200
const lower_elem_ty = switch (elem_ty .zigTypeTag ()) {
3201
- .Opaque , .Fn = > true ,
3201
+ .Opaque = > true ,
3202
+ .Fn = > ! elem_ty .fnInfo ().is_generic ,
3202
3203
.Array = > elem_ty .childType ().hasRuntimeBitsIgnoreComptime (),
3203
3204
else = > elem_ty .hasRuntimeBitsIgnoreComptime (),
3204
3205
};
@@ -4145,7 +4146,9 @@ pub const DeclGen = struct {
4145
4146
}
4146
4147
4147
4148
const is_fn_body = decl .ty .zigTypeTag () == .Fn ;
4148
- if (! is_fn_body and ! decl .ty .hasRuntimeBits ()) {
4149
+ if ((! is_fn_body and ! decl .ty .hasRuntimeBits ()) or
4150
+ (is_fn_body and decl .ty .fnInfo ().is_generic ))
4151
+ {
4149
4152
return self .lowerPtrToVoid (tv .ty );
4150
4153
}
4151
4154
Original file line number Diff line number Diff line change @@ -489,3 +489,20 @@ test "ptrCast comptime known slice to C pointer" {
489
489
var p = @ptrCast ([* c ]const u8 , s );
490
490
try std .testing .expectEqualStrings (s , std .mem .sliceTo (p , 0 ));
491
491
}
492
+
493
+ test "ptrToInt on a generic function" {
494
+ if (builtin .zig_backend == .stage2_c ) return error .SkipZigTest ; // TODO
495
+ if (builtin .zig_backend == .stage2_wasm ) return error .SkipZigTest ; // TODO
496
+ if (builtin .zig_backend == .stage2_aarch64 and builtin .os .tag != .linux ) return error .SkipZigTest ; // TODO
497
+ if (builtin .zig_backend == .stage2_x86_64 and builtin .os .tag != .linux ) return error .SkipZigTest ; // TODO
498
+
499
+ const S = struct {
500
+ fn generic (i : anytype ) @TypeOf (i ) {
501
+ return i ;
502
+ }
503
+ fn doTheTest (a : anytype ) ! void {
504
+ try expect (@ptrToInt (a ) != 0 );
505
+ }
506
+ };
507
+ try S .doTheTest (& S .generic );
508
+ }
You can’t perform that action at this time.
0 commit comments