authorgravatar for frmdstryr@protonmail.comfrmdstryr <frmdstryr@protonmail.com> 2020-10-26 13:42:23-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-26 13:29:32-07:00
log1ce09948975a148e09bf405f6a899e4fb0730ce6
tree21c96683dccb9556929bd966f7a55cf96b59a5a5
parente83334274f1d35690e4546938aff065397347943

Fix @import of empty file


3 files changed, 11 insertions(+), 4 deletions(-)

src/stage1/analyze.cpp+7-4
......@@ -1988,7 +1988,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
19881988 // behaviour when checking expected alignment with `@ptrToInt(fn_ptr)`
19891989 // or similar. This commit proposes to make `align` expressions a
19901990 // compile error when compiled to Wasm architecture.
1991 //
1991 //
19921992 // Some references:
19931993 // [1] [Mozilla: WebAssembly Tables](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#WebAssembly_tables)
19941994 // [2] [Sunfishcode's Wasm Ref Manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#indirect-call)
......@@ -8052,10 +8052,13 @@ not_integer:
80528052}
80538053
80548054Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) {
8055 size_t len;
8055 size_t len = 0xAA;
80568056 const char *contents = stage2_fetch_file(&g->stage1, buf_ptr(resolved_path), buf_len(resolved_path), &len);
8057 if (contents == nullptr)
8057 if (len == 0) {
8058 // File exists but is empty (otherwise it would be 0xAA)
8059 } else if (contents == nullptr) {
80588060 return ErrorFileNotFound;
8061 }
80598062 buf_init_from_mem(contents_buf, contents, len);
80608063 return ErrorNone;
80618064}
......@@ -9044,7 +9047,7 @@ static void resolve_llvm_types_optional(CodeGen *g, ZigType *type, ResolveStatus
90449047 8 * child_type->abi_align,
90459048 val_offset_in_bits,
90469049 ZigLLVM_DIFlags_Zero, child_llvm_di_type);
9047 di_element_types[maybe_null_index] =
9050 di_element_types[maybe_null_index] =
90489051 ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(type->llvm_di_type),
90499052 "maybe", di_file, line,
90509053 8*g->builtin_types.entry_bool->abi_size,
test/stage1/behavior/import.zig+4
......@@ -16,3 +16,7 @@ test "import in non-toplevel scope" {
1616 };
1717 expectEqual(@as(i32, 1234), S.foo());
1818}
19
20test "import empty file" {
21 const empty = @import("import/empty.zig");
22}
test/stage1/behavior/import/empty.zig created