commit 5c3325588ef4e85e85cb201ad9328fe26bbb8dca (tree)
parent a318aeed9b8ccec453e9f15415ea3fd20cb13c8d
Author: Robin Voetter <robin@voetter.nl>
Date: Sat, 19 Mar 2022 12:26:21 +0100
stage1: make type names more unique
Diffstat:
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/doc/langref.html.in b/doc/langref.html.in
@@ -3454,6 +3454,8 @@ test "aligned struct fields" {
<li>If the struct is in the {#syntax#}return{#endsyntax#} expression, it gets named after
the function it is returning from, with the parameter values serialized.</li>
<li>Otherwise, the struct gets a name such as <code>(anonymous struct at file.zig:7:38)</code>.</li>
+ <li>If the struct is declared inside another struct, it gets named after both the parent
+ struct and the name inferred by the previous rules, separated by a dot.</li>
</ul>
{#code_begin|exe|struct_name#}
const std = @import("std");
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
@@ -2188,7 +2188,7 @@ test "enum" {
try expectFmt("enum: Enum.Two\n", "enum: {X}\n", .{Enum.Two});
// test very large enum to verify ct branch quota is large enough
- try expectFmt("enum: Win32Error.INVALID_FUNCTION\n", "enum: {}\n", .{std.os.windows.Win32Error.INVALID_FUNCTION});
+ try expectFmt("enum: os.windows.win32error.Win32Error.INVALID_FUNCTION\n", "enum: {}\n", .{std.os.windows.Win32Error.INVALID_FUNCTION});
}
test "non-exhaustive enum" {
diff --git a/src/stage1/astgen.cpp b/src/stage1/astgen.cpp
@@ -7680,11 +7680,14 @@ Buf *get_anon_type_name(CodeGen *codegen, Stage1Zir *exec, const char *kind_name
if (!force_generic) {
if (exec != nullptr && exec->name != nullptr) {
- ZigType *import = get_scope_import(scope);
+ buf_resize(out_bare_name, 0);
+ if (scope->id == ScopeIdDecls) {
+ ScopeDecls *decls_scope = reinterpret_cast<ScopeDecls *>(scope);
+ append_namespace_qualification(codegen, out_bare_name, decls_scope->container_type);
+ }
+ buf_append_buf(out_bare_name, exec->name);
Buf *namespace_name = buf_alloc();
- append_namespace_qualification(codegen, namespace_name, import);
- buf_append_buf(namespace_name, exec->name);
- buf_init_from_buf(out_bare_name, exec->name);
+ buf_append_buf(namespace_name, out_bare_name);
return namespace_name;
}
if (exec != nullptr && exec->name_fn != nullptr) {
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -267,7 +267,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ });
\\}
, &[_][]const u8{
- "tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Int'",
+ "tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'",
});
ctx.objErrStage1("indexing a undefined slice at comptime",
@@ -3461,7 +3461,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ _ = field;
\\}
, &[_][]const u8{
- "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known",
+ "tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known",
});
ctx.objErrStage1("compile log statement inside function which must be comptime evaluated",