| author | |
| committer | |
| log | f4b8850002d5f617450a9d08b05519f390bd3f21 |
| tree | bed7909e1ef5f5874615261fc7d97f7a40ff02c5 |
| parent | aa60d2a688c965dcccf8e2c42afe5c180daba8fc |
| signature |
2 files changed, 26 insertions(+), 6 deletions(-)
src/ir.cpp+3-2| ... | ... | @@ -18613,10 +18613,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 18613 | 18613 | true, false, PtrLenUnknown, |
| 18614 | 18614 | 0, 0, 0, false); |
| 18615 | 18615 | fn_decl_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); |
| 18616 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { | |
| 18616 | if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) { | |
| 18617 | 18617 | fn_decl_fields[6].data.x_optional = create_const_vals(1); |
| 18618 | 18618 | ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name); |
| 18619 | init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, buf_len(fn_node->lib_name), true); | |
| 18619 | init_const_slice(ira->codegen, fn_decl_fields[6].data.x_optional, lib_name, 0, | |
| 18620 | buf_len(fn_node->lib_name), true); | |
| 18620 | 18621 | } else { |
| 18621 | 18622 | fn_decl_fields[6].data.x_optional = nullptr; |
| 18622 | 18623 | } |
test/stage1/behavior/type_info.zig+23-4| ... | ... | @@ -1,7 +1,9 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | const mem = @import("std").mem; | |
| 3 | const TypeInfo = @import("builtin").TypeInfo; | |
| 4 | const TypeId = @import("builtin").TypeId; | |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | const mem = std.mem; | |
| 4 | const builtin = @import("builtin"); | |
| 5 | const TypeInfo = builtin.TypeInfo; | |
| 6 | const TypeId = builtin.TypeId; | |
| 5 | 7 | |
| 6 | 8 | test "type info: tag type, void info" { |
| 7 | 9 | testBasic(); |
| ... | ... | @@ -317,3 +319,20 @@ test "type info: TypeId -> TypeInfo impl cast" { |
| 317 | 319 | _ = passTypeInfo(TypeId.Void); |
| 318 | 320 | _ = comptime passTypeInfo(TypeId.Void); |
| 319 | 321 | } |
| 322 | ||
| 323 | test "type info: extern fns with and without lib names" { | |
| 324 | const S = struct { | |
| 325 | extern fn bar1() void; | |
| 326 | extern "cool" fn bar2() void; | |
| 327 | }; | |
| 328 | const info = @typeInfo(S); | |
| 329 | comptime { | |
| 330 | for (info.Struct.decls) |decl| { | |
| 331 | if (std.mem.eql(u8, decl.name, "bar1")) { | |
| 332 | expect(decl.data.Fn.lib_name == null); | |
| 333 | } else { | |
| 334 | std.testing.expectEqual(([]const u8)("cool"), decl.data.Fn.lib_name.?); | |
| 335 | } | |
| 336 | } | |
| 337 | } | |
| 338 | } |