diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-08 12:27:02 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-08 12:27:02 -0500 |
| commit | d57370d3ca28db17a183157b0497c0ab25e22c19 (patch) | |
| tree | 0dfbe27beb71eabdce5add8e423f5ad5d50f8b09 /test | |
| parent | 19c1b5a33a21bdddfbbca3c65b1c0e6419c4629f (diff) | |
| parent | 64d700bfa6cea1d9a440a7431ec8d64964cdd6c1 (diff) | |
| download | zig-d57370d3ca28db17a183157b0497c0ab25e22c19.tar.gz zig-d57370d3ca28db17a183157b0497c0ab25e22c19.zip | |
Merge branch 'comptime-fields'
closes #3677
Diffstat (limited to 'test')
| -rw-r--r-- | test/compile_errors.zig | 11 | ||||
| -rw-r--r-- | test/stage1/behavior/call.zig | 8 | ||||
| -rw-r--r-- | test/stage1/behavior/struct.zig | 12 |
3 files changed, 24 insertions, 7 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 13e666f49e..3cdf8723ac 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add("comptime struct field, no init value", + \\const Foo = struct { + \\ comptime b: i32, + \\}; + \\export fn entry() void { + \\ var f: Foo = undefined; + \\} + , "tmp.zig:2:5: error: comptime struct field missing initialization value"); + cases.add( "bad usage of @call", \\export fn entry1() void { @@ -32,7 +41,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:15:43: error: unable to evaluate constant expression", ); - cases.add( + cases.add("exported async function", \\export async fn foo() void {} , "tmp.zig:1:1: error: exported function cannot be async"); diff --git a/test/stage1/behavior/call.zig b/test/stage1/behavior/call.zig index d68fb64d02..1280224fa3 100644 --- a/test/stage1/behavior/call.zig +++ b/test/stage1/behavior/call.zig @@ -37,12 +37,12 @@ test "tuple parameters" { comptime expect(@call(.{}, add, .{ 12, 34 }) == 46); { const separate_args0 = .{ a, b }; - //TODO const separate_args1 = .{ a, 34 }; + const separate_args1 = .{ a, 34 }; const separate_args2 = .{ 12, 34 }; - //TODO const separate_args3 = .{ 12, b }; + const separate_args3 = .{ 12, b }; expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46); - // TODO expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46); + expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46); expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46); - // TODO expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46); + expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46); } } diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index 408f5da687..91f00006da 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -775,8 +775,6 @@ test "anonymous struct literal assigned to variable" { expect(vec.@"0" == 22); expect(vec.@"1" == 55); expect(vec.@"2" == 99); - vec.@"1" += 1; - expect(vec.@"1" == 56); } test "struct with var field" { @@ -791,3 +789,13 @@ test "struct with var field" { expect(pt.x == 1); expect(pt.y == 2); } + +test "comptime struct field" { + const T = struct { + a: i32, + comptime b: i32 = 1234, + }; + + var foo: T = undefined; + comptime expect(foo.b == 1234); +} |
