| author | |
| committer | |
| log | d9dd50d74c282aefcb89ca922523916b88a6236f |
| tree | 56a6f6658059327ad975afbf20f6ace272a98805 |
| parent | 8e19bdfc797cb419bddb4334e7d81abd382c11d9 |
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 * |
| 2922 | 2922 | continue; |
| 2923 | 2923 | } |
| 2924 | 2924 | |
| 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); | |
| 2926 | 2930 | if (existing_entry) { |
| 2927 | 2931 | Tld *existing_decl = existing_entry->value; |
| 2928 | 2932 | if (existing_decl != target_tld) { |
| 2929 | 2933 | ErrorMsg *msg = add_node_error(g, dst_use_node, |
| 2930 | 2934 | buf_sprintf("import of '%s' overrides existing definition", |
| 2931 | buf_ptr(target_tld->name))); | |
| 2935 | buf_ptr(target_tld_name))); | |
| 2932 | 2936 | add_error_note(g, msg, existing_decl->source_node, buf_sprintf("previous definition here")); |
| 2933 | 2937 | add_error_note(g, msg, target_tld->source_node, buf_sprintf("imported definition here")); |
| 2934 | 2938 | } |
| ... | ... | @@ -2956,6 +2960,12 @@ void resolve_use_decl(CodeGen *g, AstNode *node) { |
| 2956 | 2960 | void preview_use_decl(CodeGen *g, AstNode *node) { |
| 2957 | 2961 | assert(node->type == NodeTypeUse); |
| 2958 | 2962 | |
| 2963 | if (node->data.use.resolution == TldResolutionOk || | |
| 2964 | node->data.use.resolution == TldResolutionInvalid) | |
| 2965 | { | |
| 2966 | return; | |
| 2967 | } | |
| 2968 | ||
| 2959 | 2969 | node->data.use.resolution = TldResolutionResolving; |
| 2960 | 2970 | IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base, |
| 2961 | 2971 | node->data.use.expr, g->builtin_types.entry_namespace, nullptr); |
std/build.zig+2-2| ... | ... | @@ -979,7 +979,7 @@ pub const LibExeObjStep = struct { |
| 979 | 979 | |
| 980 | 980 | for (builder.include_paths.toSliceConst()) |include_path| { |
| 981 | 981 | %%zig_args.append("-isystem"); |
| 982 | %%zig_args.append(include_path); | |
| 982 | %%zig_args.append(builder.pathFromRoot(include_path)); | |
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | for (builder.rpaths.toSliceConst()) |rpath| { |
| ... | ... | @@ -1086,7 +1086,7 @@ pub const TestStep = struct { |
| 1086 | 1086 | |
| 1087 | 1087 | for (builder.include_paths.toSliceConst()) |include_path| { |
| 1088 | 1088 | %%zig_args.append("-isystem"); |
| 1089 | %%zig_args.append(include_path); | |
| 1089 | %%zig_args.append(builder.pathFromRoot(include_path)); | |
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | for (builder.rpaths.toSliceConst()) |rpath| { |
test/build_examples.zig+1| ... | ... | @@ -9,4 +9,5 @@ pub fn addCases(cases: &tests.BuildExamplesContext) { |
| 9 | 9 | cases.addBuildFile("example/mix_o_files/build.zig"); |
| 10 | 10 | cases.addBuildFile("test/standalone/issue_339/build.zig"); |
| 11 | 11 | cases.addBuildFile("test/standalone/pkg_import/build.zig"); |
| 12 | cases.addBuildFile("test/standalone/use_alias/build.zig"); | |
| 12 | 13 | } |
test/standalone/use_alias/build.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const Builder = @import("std").build.Builder; | |
| 2 | ||
| 3 | pub 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 @@ |
| 1 | pub use @cImport(@cInclude("foo.h")); |
test/standalone/use_alias/foo.h created+4| ... | ... | @@ -0,0 +1,4 @@ |
| 1 | struct Foo { | |
| 2 | int a; | |
| 3 | int b; | |
| 4 | }; |
test/standalone/use_alias/main.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | const c = @import("c.zig"); | |
| 2 | const assert = @import("std").debug.assert; | |
| 3 | ||
| 4 | test "symbol exists" { | |
| 5 | var foo = c.Foo { | |
| 6 | .a = 1, | |
| 7 | .b = 1, | |
| 8 | }; | |
| 9 | assert(foo.a + foo.b == 2); | |
| 10 | } |