parent
32821e7098
commit
ea21d2beb6
@ -2072,6 +2072,18 @@ static VariableTableEntry *add_local_var(CodeGen *g, AstNode *source_node, Block
|
|||||||
if (existing_var) {
|
if (existing_var) {
|
||||||
add_node_error(g, source_node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
|
add_node_error(g, source_node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
|
||||||
variable_entry->type = g->builtin_types.entry_invalid;
|
variable_entry->type = g->builtin_types.entry_invalid;
|
||||||
|
} else {
|
||||||
|
auto primitive_table_entry = g->primitive_type_table.maybe_get(name);
|
||||||
|
TypeTableEntry *type;
|
||||||
|
if (primitive_table_entry) {
|
||||||
|
type = primitive_table_entry->value;
|
||||||
|
} else {
|
||||||
|
type = find_container(context, name);
|
||||||
|
}
|
||||||
|
if (type) {
|
||||||
|
add_node_error(g, source_node, buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
|
||||||
|
variable_entry->type = g->builtin_types.entry_invalid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context->variable_table.put(&variable_entry->name, variable_entry);
|
context->variable_table.put(&variable_entry->name, variable_entry);
|
||||||
|
@ -1501,6 +1501,16 @@ const foo = []u16{.x = 1024,};
|
|||||||
add_compile_fail_case("type variables must be constant", R"SOURCE(
|
add_compile_fail_case("type variables must be constant", R"SOURCE(
|
||||||
var foo = u8;
|
var foo = u8;
|
||||||
)SOURCE", 1, ".tmp_source.zig:2:1: error: variable of type 'type' must be constant");
|
)SOURCE", 1, ".tmp_source.zig:2:1: error: variable of type 'type' must be constant");
|
||||||
|
|
||||||
|
add_compile_fail_case("variables shadowing types", R"SOURCE(
|
||||||
|
struct Foo {}
|
||||||
|
struct Bar {}
|
||||||
|
|
||||||
|
fn f(Foo: i32) => {
|
||||||
|
var Bar : i32;
|
||||||
|
}
|
||||||
|
)SOURCE", 2, ".tmp_source.zig:5:6: error: variable shadows type 'Foo'",
|
||||||
|
".tmp_source.zig:6:5: error: variable shadows type 'Bar'");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_compiler_invocation(TestCase *test_case) {
|
static void print_compiler_invocation(TestCase *test_case) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user