mirror of
https://github.com/ziglang/zig.git
synced 2026-01-24 08:15:23 +00:00
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.
This commit is contained in:
parent
171102ea7c
commit
9be2f76741
@ -8623,7 +8623,7 @@ test "integer truncation" {
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@typeName#}
|
||||
<pre>{#syntax#}@typeName(T: type) [N]u8{#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@typeName(T: type) *const [N:0]u8{#endsyntax#}</pre>
|
||||
<p>
|
||||
This function returns the string representation of a type, as
|
||||
an array. It is equivalent to a string literal of the type name.
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user