mirror of
https://github.com/ziglang/zig.git
synced 2026-02-02 04:33:37 +00:00
fix detection of @import and @c_import inside fn body
This commit is contained in:
parent
5df091fea9
commit
f72c36cd37
@ -4021,8 +4021,8 @@ static TypeTableEntry *analyze_import(CodeGen *g, ImportTableEntry *import, Bloc
|
||||
{
|
||||
assert(node->type == NodeTypeFnCallExpr);
|
||||
|
||||
if (context != import->block_context) {
|
||||
add_node_error(g, node, buf_sprintf("@import valid only at top level scope"));
|
||||
if (context->fn_entry) {
|
||||
add_node_error(g, node, buf_sprintf("@import invalid inside function bodies"));
|
||||
return g->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
@ -4096,8 +4096,8 @@ static TypeTableEntry *analyze_c_import(CodeGen *g, ImportTableEntry *parent_imp
|
||||
{
|
||||
assert(node->type == NodeTypeFnCallExpr);
|
||||
|
||||
if (parent_context != parent_import->block_context) {
|
||||
add_node_error(g, node, buf_sprintf("@c_import valid only at top level scope"));
|
||||
if (parent_context->fn_entry) {
|
||||
add_node_error(g, node, buf_sprintf("@c_import invalid inside function bodies"));
|
||||
return g->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
|
||||
@ -1764,6 +1764,12 @@ fn f(n: Number) -> i32 {
|
||||
}
|
||||
}
|
||||
)SOURCE", 1, ".tmp_source.zig:9:5: error: enumeration value 'Four' not handled in switch");
|
||||
|
||||
add_compile_fail_case("import inside function body", R"SOURCE(
|
||||
fn f() {
|
||||
const std = @import("std");
|
||||
}
|
||||
)SOURCE", 1, ".tmp_source.zig:3:17: error: @import invalid inside function bodies");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user