implement compile time string concatenation

See #76
This commit is contained in:
Andrew Kelley
2016-01-25 21:56:29 -07:00
parent 1d68150242
commit a3e288ab5b
9 changed files with 98 additions and 3 deletions

View File

@@ -1279,6 +1279,13 @@ pub fn main(args: [][]u8) -> %void {
%%stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("string concatenation", R"SOURCE(
import "std.zig";
pub fn main(args: [][]u8) -> %void {
%%stdout.printf("OK" ++ " IT " ++ "WORKED\n");
}
)SOURCE", "OK IT WORKED\n");
}
@@ -1645,6 +1652,12 @@ extern {
const x = foo();
)SOURCE", 1, ".tmp_source.zig:5:11: error: global variable initializer requires constant expression");
add_compile_fail_case("non compile time string concatenation", R"SOURCE(
fn f(s: []u8) -> []u8 {
s ++ "foo"
}
)SOURCE", 1, ".tmp_source.zig:3:5: error: string concatenation requires constant expression");
}
static void print_compiler_invocation(TestCase *test_case) {