authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-20 04:03:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-20 04:03:36-04:00
logd9dd50d74c282aefcb89ca922523916b88a6236f
tree56a6f6658059327ad975afbf20f6ace272a98805
parent8e19bdfc797cb419bddb4334e7d81abd382c11d9

fix not propagating parseh aliases through pub use decls


7 files changed, 41 insertions(+), 4 deletions(-)

src/analyze.cpp+12-2
......@@ -2922,13 +2922,17 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
29222922 continue;
29232923 }
29242924
2925 auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld->name, target_tld);
2925 // Note: target_tld->name is not necessarily equal to entry->key because
2926 // of aliases that parseh uses.
2927 Buf *target_tld_name = entry->key;
2928
2929 auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld);
29262930 if (existing_entry) {
29272931 Tld *existing_decl = existing_entry->value;
29282932 if (existing_decl != target_tld) {
29292933 ErrorMsg *msg = add_node_error(g, dst_use_node,
29302934 buf_sprintf("import of '%s' overrides existing definition",
2931 buf_ptr(target_tld->name)));
2935 buf_ptr(target_tld_name)));
29322936 add_error_note(g, msg, existing_decl->source_node, buf_sprintf("previous definition here"));
29332937 add_error_note(g, msg, target_tld->source_node, buf_sprintf("imported definition here"));
29342938 }
......@@ -2956,6 +2960,12 @@ void resolve_use_decl(CodeGen *g, AstNode *node) {
29562960void preview_use_decl(CodeGen *g, AstNode *node) {
29572961 assert(node->type == NodeTypeUse);
29582962
2963 if (node->data.use.resolution == TldResolutionOk ||
2964 node->data.use.resolution == TldResolutionInvalid)
2965 {
2966 return;
2967 }
2968
29592969 node->data.use.resolution = TldResolutionResolving;
29602970 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
29612971 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
std/build.zig+2-2
......@@ -979,7 +979,7 @@ pub const LibExeObjStep = struct {
979979
980980 for (builder.include_paths.toSliceConst()) |include_path| {
981981 %%zig_args.append("-isystem");
982 %%zig_args.append(include_path);
982 %%zig_args.append(builder.pathFromRoot(include_path));
983983 }
984984
985985 for (builder.rpaths.toSliceConst()) |rpath| {
......@@ -1086,7 +1086,7 @@ pub const TestStep = struct {
10861086
10871087 for (builder.include_paths.toSliceConst()) |include_path| {
10881088 %%zig_args.append("-isystem");
1089 %%zig_args.append(include_path);
1089 %%zig_args.append(builder.pathFromRoot(include_path));
10901090 }
10911091
10921092 for (builder.rpaths.toSliceConst()) |rpath| {
test/build_examples.zig+1
......@@ -9,4 +9,5 @@ pub fn addCases(cases: &tests.BuildExamplesContext) {
99 cases.addBuildFile("example/mix_o_files/build.zig");
1010 cases.addBuildFile("test/standalone/issue_339/build.zig");
1111 cases.addBuildFile("test/standalone/pkg_import/build.zig");
12 cases.addBuildFile("test/standalone/use_alias/build.zig");
1213}
test/standalone/use_alias/build.zig created+11
......@@ -0,0 +1,11 @@
1const Builder = @import("std").build.Builder;
2
3pub fn build(b: &Builder) {
4 b.addCIncludePath(".");
5
6 const main = b.addTest("main.zig");
7 main.setBuildMode(b.standardReleaseOptions());
8
9 const test_step = b.step("test", "Test it");
10 test_step.dependOn(&main.step);
11}
test/standalone/use_alias/c.zig created+1
......@@ -0,0 +1 @@
1pub use @cImport(@cInclude("foo.h"));
test/standalone/use_alias/foo.h created+4
......@@ -0,0 +1,4 @@
1struct Foo {
2 int a;
3 int b;
4};
test/standalone/use_alias/main.zig created+10
......@@ -0,0 +1,10 @@
1const c = @import("c.zig");
2const assert = @import("std").debug.assert;
3
4test "symbol exists" {
5 var foo = c.Foo {
6 .a = 1,
7 .b = 1,
8 };
9 assert(foo.a + foo.b == 2);
10}