diff options
| author | Daniele Cocca <daniele.cocca@gmail.com> | 2021-04-28 01:13:47 +0100 |
|---|---|---|
| committer | Daniele Cocca <dcocca@google.com> | 2021-06-16 22:03:02 +0100 |
| commit | 9be2f767417ef4eb69f35b67348bb3e2ec752d4a (patch) | |
| tree | ec3eb55e45146939458cf801ea07b78080ef81a6 /test/behavior | |
| parent | 171102ea7ca3a11113d2ccfb7206b0eaddab19ac (diff) | |
| download | zig-9be2f767417ef4eb69f35b67348bb3e2ec752d4a.tar.gz zig-9be2f767417ef4eb69f35b67348bb3e2ec752d4a.zip | |
typeName: amend return type to string literal
This was already the case, but the documentation failed to point out
that the returned value is of type `*const [N:0]u8`, i.e. that of a
string literal.
Also adds a behavioral test to assert that this is the case.
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/bugs/3779.zig | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/behavior/bugs/3779.zig b/test/behavior/bugs/3779.zig index 5423a6f265..2c92236e20 100644 --- a/test/behavior/bugs/3779.zig +++ b/test/behavior/bugs/3779.zig @@ -19,3 +19,13 @@ test "@errorName() returns a string literal" { try std.testing.expectEqualStrings("TestErrorCode", error_name); try std.testing.expectEqualStrings("TestErrorCode", ptr_error_name[0..error_name.len]); } + +const TestType = struct {}; +const type_name = @typeName(TestType); +const ptr_type_name: [*:0]const u8 = type_name; + +test "@typeName() returns a string literal" { + try std.testing.expectEqual(*const [type_name.len:0]u8, @TypeOf(type_name)); + try std.testing.expectEqualStrings("TestType", type_name); + try std.testing.expectEqualStrings("TestType", ptr_type_name[0..type_name.len]); +} |
