| author | |
| committer | |
| log | fe6249348f615c975a2db53bb0c93f83bd2a281b |
| tree | e059a560361900c2d6e0d226be20cebc9ea0c74e |
| parent | fb09093d95f2dc9bf454ba0d1d489316311adffc |
This prevents sema from creating new decls for the functions and
passing them to the backends as non-function decls.
Closes #125012 files changed, 22 insertions(+), 0 deletions(-)
src/Sema.zig+7| ... | ... | @@ -27404,6 +27404,13 @@ fn analyzeRef( |
| 27404 | 27404 | const operand_ty = sema.typeOf(operand); |
| 27405 | 27405 | |
| 27406 | 27406 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 27407 | switch (val.tag()) { | |
| 27408 | .extern_fn, .function => { | |
| 27409 | const decl_index = val.pointerDecl().?; | |
| 27410 | return sema.analyzeDeclRef(decl_index); | |
| 27411 | }, | |
| 27412 | else => {}, | |
| 27413 | } | |
| 27407 | 27414 | var anon_decl = try block.startAnonDecl(); |
| 27408 | 27415 | defer anon_decl.deinit(); |
| 27409 | 27416 | return sema.analyzeDeclRef(try anon_decl.finish( |
test/behavior/eval.zig+15| ... | ... | @@ -1507,3 +1507,18 @@ test "inline call in @TypeOf inherits is_inline property" { |
| 1507 | 1507 | }; |
| 1508 | 1508 | try expect(S.T == void); |
| 1509 | 1509 | } |
| 1510 | ||
| 1511 | test "comptime function turns function value to function pointer" { | |
| 1512 | const S = struct { | |
| 1513 | fn fnPtr(function: anytype) *const @TypeOf(function) { | |
| 1514 | return &function; | |
| 1515 | } | |
| 1516 | fn Nil() u8 { | |
| 1517 | return 0; | |
| 1518 | } | |
| 1519 | const foo = &[_]*const fn () u8{ | |
| 1520 | fnPtr(Nil), | |
| 1521 | }; | |
| 1522 | }; | |
| 1523 | comptime try expect(S.foo[0] == &S.Nil); | |
| 1524 | } |