authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-03-01 17:59:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-03-01 17:59:56-07:00
logf72c36cd37a383ca7ca9e09cb6a665dfe2c73365
tree3d00619cc5388f62dab00f0abbd2bf968fbb8b18
parent5df091fea98e91536f95e3b4bd5bcb0881f06989

fix detection of @import and @c_import inside fn body


2 files changed, 10 insertions(+), 4 deletions(-)

src/analyze.cpp+4-4
......@@ -4021,8 +4021,8 @@ static TypeTableEntry *analyze_import(CodeGen *g, ImportTableEntry *import, Bloc
40214021{
40224022 assert(node->type == NodeTypeFnCallExpr);
40234023
4024 if (context != import->block_context) {
4025 add_node_error(g, node, buf_sprintf("@import valid only at top level scope"));
4024 if (context->fn_entry) {
4025 add_node_error(g, node, buf_sprintf("@import invalid inside function bodies"));
40264026 return g->builtin_types.entry_invalid;
40274027 }
40284028
......@@ -4096,8 +4096,8 @@ static TypeTableEntry *analyze_c_import(CodeGen *g, ImportTableEntry *parent_imp
40964096{
40974097 assert(node->type == NodeTypeFnCallExpr);
40984098
4099 if (parent_context != parent_import->block_context) {
4100 add_node_error(g, node, buf_sprintf("@c_import valid only at top level scope"));
4099 if (parent_context->fn_entry) {
4100 add_node_error(g, node, buf_sprintf("@c_import invalid inside function bodies"));
41014101 return g->builtin_types.entry_invalid;
41024102 }
41034103
test/run_tests.cpp+6
......@@ -1764,6 +1764,12 @@ fn f(n: Number) -> i32 {
17641764 }
17651765}
17661766 )SOURCE", 1, ".tmp_source.zig:9:5: error: enumeration value 'Four' not handled in switch");
1767
1768 add_compile_fail_case("import inside function body", R"SOURCE(
1769fn f() {
1770 const std = @import("std");
1771}
1772 )SOURCE", 1, ".tmp_source.zig:3:17: error: @import invalid inside function bodies");
17671773}
17681774
17691775//////////////////////////////////////////////////////////////////////////////