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...@@ -4021,8 +4021,8 @@ static TypeTableEntry *analyze_import(CodeGen *g, ImportTableEntry *import, Bloc
4021{4021{
4022 assert(node->type == NodeTypeFnCallExpr);4022 assert(node->type == NodeTypeFnCallExpr);
40234023
4024 if (context != import->block_context) {4024 if (context->fn_entry) {
4025 add_node_error(g, node, buf_sprintf("@import valid only at top level scope"));4025 add_node_error(g, node, buf_sprintf("@import invalid inside function bodies"));
4026 return g->builtin_types.entry_invalid;4026 return g->builtin_types.entry_invalid;
4027 }4027 }
40284028
...@@ -4096,8 +4096,8 @@ static TypeTableEntry *analyze_c_import(CodeGen *g, ImportTableEntry *parent_imp...@@ -4096,8 +4096,8 @@ static TypeTableEntry *analyze_c_import(CodeGen *g, ImportTableEntry *parent_imp
4096{4096{
4097 assert(node->type == NodeTypeFnCallExpr);4097 assert(node->type == NodeTypeFnCallExpr);
40984098
4099 if (parent_context != parent_import->block_context) {4099 if (parent_context->fn_entry) {
4100 add_node_error(g, node, buf_sprintf("@c_import valid only at top level scope"));4100 add_node_error(g, node, buf_sprintf("@c_import invalid inside function bodies"));
4101 return g->builtin_types.entry_invalid;4101 return g->builtin_types.entry_invalid;
4102 }4102 }
41034103
test/run_tests.cpp+6
...@@ -1764,6 +1764,12 @@ fn f(n: Number) -> i32 {...@@ -1764,6 +1764,12 @@ fn f(n: Number) -> i32 {
1764 }1764 }
1765}1765}
1766 )SOURCE", 1, ".tmp_source.zig:9:5: error: enumeration value 'Four' not handled in switch");1766 )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");
1767}1773}
17681774
1769//////////////////////////////////////////////////////////////////////////////1775//////////////////////////////////////////////////////////////////////////////