diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-05-26 16:44:13 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-05-26 16:44:13 -0400 |
| commit | d6b01931ef8a04777ae198af323c2b6ba998f7b1 (patch) | |
| tree | afa92361832d1b071fb029678524a4b7f01174f8 /test | |
| parent | c42c91ee7c630d47e6adc0a940b5f10bbe04d13a (diff) | |
| download | zig-d6b01931ef8a04777ae198af323c2b6ba998f7b1.tar.gz zig-d6b01931ef8a04777ae198af323c2b6ba998f7b1.zip | |
implicitly cast by value var args parameters to const references
See #336
Diffstat (limited to 'test')
| -rw-r--r-- | test/cases/cast.zig | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/cases/cast.zig b/test/cases/cast.zig index a16ea1263c..3929e33c12 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -206,3 +206,24 @@ fn testResolveUndefWithInt(b: bool, x: i32) { assert(value == x); } } + +test "implicit cast from &const [N]T to []const T" { + testCastConstArrayRefToConstSlice(); + comptime testCastConstArrayRefToConstSlice(); +} + +fn testCastConstArrayRefToConstSlice() { + const blah = "aoeu"; + const const_array_ref = &blah; + assert(@typeOf(const_array_ref) == &const [4]u8); + const slice: []const u8 = const_array_ref; + assert(mem.eql(u8, slice, "aoeu")); +} + +test "var args implicitly casts by value arg to const ref" { + foo("hello"); +} + +fn foo(args: ...) { + assert(@typeOf(args[0]) == &const [5]u8); +} |
