| author | |
| committer | |
| log | cd2f65ff6ace9f1e426d5e8a4721666d347b289d |
| tree | 54231420872d0d852ad2f8bc2e2f3bbabd88ac7a |
| parent | 987768778a67538299f84a6ab7ff0ca65f69d2ac |
closes #4233 files changed, 25 insertions(+), 9 deletions(-)
src/analyze.cpp+17-6| ... | @@ -2028,12 +2028,23 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) { | ... | @@ -2028,12 +2028,23 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) { |
| 2028 | } | 2028 | } |
| 2029 | } | 2029 | } |
| 2030 | 2030 | ||
| 2031 | auto entry = decls_scope->decl_table.put_unique(tld->name, tld); | 2031 | { |
| 2032 | if (entry) { | 2032 | auto entry = decls_scope->decl_table.put_unique(tld->name, tld); |
| 2033 | Tld *other_tld = entry->value; | 2033 | if (entry) { |
| 2034 | ErrorMsg *msg = add_node_error(g, tld->source_node, buf_sprintf("redefinition of '%s'", buf_ptr(tld->name))); | 2034 | Tld *other_tld = entry->value; |
| 2035 | add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition is here")); | 2035 | ErrorMsg *msg = add_node_error(g, tld->source_node, buf_sprintf("redefinition of '%s'", buf_ptr(tld->name))); |
| 2036 | return; | 2036 | add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition is here")); |
| 2037 | return; | ||
| 2038 | } | ||
| 2039 | } | ||
| 2040 | |||
| 2041 | { | ||
| 2042 | auto entry = g->primitive_type_table.maybe_get(tld->name); | ||
| 2043 | if (entry) { | ||
| 2044 | TypeTableEntry *type = entry->value; | ||
| 2045 | add_node_error(g, tld->source_node, | ||
| 2046 | buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name))); | ||
| 2047 | } | ||
| 2037 | } | 2048 | } |
| 2038 | } | 2049 | } |
| 2039 | 2050 |
test/cases/struct.zig-3| ... | @@ -202,7 +202,6 @@ test "packed struct" { | ... | @@ -202,7 +202,6 @@ test "packed struct" { |
| 202 | 202 | ||
| 203 | 203 | ||
| 204 | const u2 = @IntType(false, 2); | 204 | const u2 = @IntType(false, 2); |
| 205 | const u3 = @IntType(false, 3); | ||
| 206 | 205 | ||
| 207 | const BitField1 = packed struct { | 206 | const BitField1 = packed struct { |
| 208 | a: u3, | 207 | a: u3, |
| ... | @@ -374,8 +373,6 @@ test "runtime struct initialization of bitfield" { | ... | @@ -374,8 +373,6 @@ test "runtime struct initialization of bitfield" { |
| 374 | assert(s2.y == u4(x2)); | 373 | assert(s2.y == u4(x2)); |
| 375 | } | 374 | } |
| 376 | 375 | ||
| 377 | const u4 = @IntType(false, 4); | ||
| 378 | |||
| 379 | var x1 = u4(1); | 376 | var x1 = u4(1); |
| 380 | var x2 = u8(2); | 377 | var x2 = u8(2); |
| 381 | 378 |
test/compile_errors.zig+8| ... | @@ -1987,4 +1987,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { | ... | @@ -1987,4 +1987,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1987 | \\} | 1987 | \\} |
| 1988 | , | 1988 | , |
| 1989 | ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'"); | 1989 | ".tmp_source.zig:2:17: error: expected type 'u3', found 'u8'"); |
| 1990 | |||
| 1991 | cases.add("globally shadowing a primitive type", | ||
| 1992 | \\const u16 = @intType(false, 8); | ||
| 1993 | \\export fn entry() { | ||
| 1994 | \\ const a: u16 = 300; | ||
| 1995 | \\} | ||
| 1996 | , | ||
| 1997 | ".tmp_source.zig:1:1: error: declaration shadows type 'u16'"); | ||
| 1990 | } | 1998 | } |