| ... | @@ -256,6 +256,23 @@ static void add_compiling_test_cases(void) { | ... | @@ -256,6 +256,23 @@ static void add_compiling_test_cases(void) { |
| 256 | exit(0); | 256 | exit(0); |
| 257 | } | 257 | } |
| 258 | )SOURCE", "loop\nloop\nloop\n"); | 258 | )SOURCE", "loop\nloop\nloop\n"); |
| | 259 | |
| | 260 | add_simple_case("local variables", R"SOURCE( |
| | 261 | #link("c") |
| | 262 | extern { |
| | 263 | fn puts(s: *const u8) -> i32; |
| | 264 | fn exit(code: i32) -> unreachable; |
| | 265 | } |
| | 266 | |
| | 267 | export fn _start() -> unreachable { |
| | 268 | let a : i32 = 1; |
| | 269 | let b = 2; |
| | 270 | if (a + b == 3) { |
| | 271 | puts("OK"); |
| | 272 | } |
| | 273 | exit(0); |
| | 274 | } |
| | 275 | )SOURCE", "OK\n"); |
| 259 | } | 276 | } |
| 260 | | 277 | |
| 261 | static void add_compile_failure_test_cases(void) { | 278 | static void add_compile_failure_test_cases(void) { |
| ... | @@ -340,6 +357,31 @@ done: | ... | @@ -340,6 +357,31 @@ done: |
| 340 | fn b() {} | 357 | fn b() {} |
| 341 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); | 358 | )SOURCE", 1, ".tmp_source.zig:4:5: error: unreachable code"); |
| 342 | | 359 | |
| | 360 | add_compile_fail_case("parameter redeclaration", R"SOURCE( |
| | 361 | fn f(a : i32, a : i32) { |
| | 362 | } |
| | 363 | )SOURCE", 1, ".tmp_source.zig:2:1: error: redeclaration of parameter 'a'."); |
| | 364 | |
| | 365 | add_compile_fail_case("local variable redeclaration", R"SOURCE( |
| | 366 | fn f() { |
| | 367 | let a : i32 = 0; |
| | 368 | let a = 0; |
| | 369 | } |
| | 370 | )SOURCE", 1, ".tmp_source.zig:4:5: error: redeclaration of variable 'a'."); |
| | 371 | |
| | 372 | add_compile_fail_case("local variable redeclares parameter", R"SOURCE( |
| | 373 | fn f(a : i32) { |
| | 374 | let a = 0; |
| | 375 | } |
| | 376 | )SOURCE", 1, ".tmp_source.zig:3:5: error: redeclaration of variable 'a'."); |
| | 377 | |
| | 378 | add_compile_fail_case("variable has wrong type", R"SOURCE( |
| | 379 | fn f() -> i32 { |
| | 380 | let a = "a"; |
| | 381 | a |
| | 382 | } |
| | 383 | )SOURCE", 1, ".tmp_source.zig:2:15: error: type mismatch. expected i32. got *const u8"); |
| | 384 | |
| 343 | } | 385 | } |
| 344 | | 386 | |
| 345 | static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) { | 387 | static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) { |