Commit d9dd50d74c
Changed files (7)
src/analyze.cpp
@@ -2922,13 +2922,17 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
continue;
}
- auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld->name, target_tld);
+ // Note: target_tld->name is not necessarily equal to entry->key because
+ // of aliases that parseh uses.
+ Buf *target_tld_name = entry->key;
+
+ auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld);
if (existing_entry) {
Tld *existing_decl = existing_entry->value;
if (existing_decl != target_tld) {
ErrorMsg *msg = add_node_error(g, dst_use_node,
buf_sprintf("import of '%s' overrides existing definition",
- buf_ptr(target_tld->name)));
+ buf_ptr(target_tld_name)));
add_error_note(g, msg, existing_decl->source_node, buf_sprintf("previous definition here"));
add_error_note(g, msg, target_tld->source_node, buf_sprintf("imported definition here"));
}
@@ -2956,6 +2960,12 @@ void resolve_use_decl(CodeGen *g, AstNode *node) {
void preview_use_decl(CodeGen *g, AstNode *node) {
assert(node->type == NodeTypeUse);
+ if (node->data.use.resolution == TldResolutionOk ||
+ node->data.use.resolution == TldResolutionInvalid)
+ {
+ return;
+ }
+
node->data.use.resolution = TldResolutionResolving;
IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
std/build.zig
@@ -979,7 +979,7 @@ pub const LibExeObjStep = struct {
for (builder.include_paths.toSliceConst()) |include_path| {
%%zig_args.append("-isystem");
- %%zig_args.append(include_path);
+ %%zig_args.append(builder.pathFromRoot(include_path));
}
for (builder.rpaths.toSliceConst()) |rpath| {
@@ -1086,7 +1086,7 @@ pub const TestStep = struct {
for (builder.include_paths.toSliceConst()) |include_path| {
%%zig_args.append("-isystem");
- %%zig_args.append(include_path);
+ %%zig_args.append(builder.pathFromRoot(include_path));
}
for (builder.rpaths.toSliceConst()) |rpath| {
test/standalone/use_alias/build.zig
@@ -0,0 +1,11 @@
+const Builder = @import("std").build.Builder;
+
+pub fn build(b: &Builder) {
+ b.addCIncludePath(".");
+
+ const main = b.addTest("main.zig");
+ main.setBuildMode(b.standardReleaseOptions());
+
+ const test_step = b.step("test", "Test it");
+ test_step.dependOn(&main.step);
+}
test/standalone/use_alias/c.zig
@@ -0,0 +1,1 @@
+pub use @cImport(@cInclude("foo.h"));
test/standalone/use_alias/foo.h
@@ -0,0 +1,4 @@
+struct Foo {
+ int a;
+ int b;
+};
test/standalone/use_alias/main.zig
@@ -0,0 +1,10 @@
+const c = @import("c.zig");
+const assert = @import("std").debug.assert;
+
+test "symbol exists" {
+ var foo = c.Foo {
+ .a = 1,
+ .b = 1,
+ };
+ assert(foo.a + foo.b == 2);
+}
test/build_examples.zig
@@ -9,4 +9,5 @@ pub fn addCases(cases: &tests.BuildExamplesContext) {
cases.addBuildFile("example/mix_o_files/build.zig");
cases.addBuildFile("test/standalone/issue_339/build.zig");
cases.addBuildFile("test/standalone/pkg_import/build.zig");
+ cases.addBuildFile("test/standalone/use_alias/build.zig");
}