diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-08-20 04:03:36 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-08-20 04:03:36 -0400 |
| commit | d9dd50d74c282aefcb89ca922523916b88a6236f (patch) | |
| tree | 56a6f6658059327ad975afbf20f6ace272a98805 | |
| parent | 8e19bdfc797cb419bddb4334e7d81abd382c11d9 (diff) | |
| download | zig-d9dd50d74c282aefcb89ca922523916b88a6236f.tar.gz zig-d9dd50d74c282aefcb89ca922523916b88a6236f.zip | |
fix not propagating parseh aliases through pub use decls
| -rw-r--r-- | src/analyze.cpp | 14 | ||||
| -rw-r--r-- | std/build.zig | 4 | ||||
| -rw-r--r-- | test/build_examples.zig | 1 | ||||
| -rw-r--r-- | test/standalone/use_alias/build.zig | 11 | ||||
| -rw-r--r-- | test/standalone/use_alias/c.zig | 1 | ||||
| -rw-r--r-- | test/standalone/use_alias/foo.h | 4 | ||||
| -rw-r--r-- | test/standalone/use_alias/main.zig | 10 |
7 files changed, 41 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 05ec20aced..0b43f2d1e4 100644 --- a/src/analyze.cpp +++ b/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); diff --git a/std/build.zig b/std/build.zig index 99900a1700..7a40e97f52 100644 --- a/std/build.zig +++ b/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| { diff --git a/test/build_examples.zig b/test/build_examples.zig index 7ee87b2a9b..239f7e8b7d 100644 --- a/test/build_examples.zig +++ b/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"); } diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig new file mode 100644 index 0000000000..03398f1a41 --- /dev/null +++ b/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); +} diff --git a/test/standalone/use_alias/c.zig b/test/standalone/use_alias/c.zig new file mode 100644 index 0000000000..1bc325b117 --- /dev/null +++ b/test/standalone/use_alias/c.zig @@ -0,0 +1 @@ +pub use @cImport(@cInclude("foo.h")); diff --git a/test/standalone/use_alias/foo.h b/test/standalone/use_alias/foo.h new file mode 100644 index 0000000000..900ab6b51a --- /dev/null +++ b/test/standalone/use_alias/foo.h @@ -0,0 +1,4 @@ +struct Foo { + int a; + int b; +}; diff --git a/test/standalone/use_alias/main.zig b/test/standalone/use_alias/main.zig new file mode 100644 index 0000000000..40cab9ad8a --- /dev/null +++ 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); +} |
