From 7db39384f7384b73c51dd9cab5b23ad0a3699fd0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 23 May 2022 19:49:04 -0700 Subject: [PATCH] move bound function behavior test to compile error test --- test/behavior/eval.zig | 22 ------------------- ... on bound fn referring to var instance.zig | 20 +++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 test/cases/compile_errors/call method on bound fn referring to var instance.zig diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 2d53122706..3ffa0a3a12 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -572,28 +572,6 @@ test "inlined loop has array literal with elided runtime scope on first iteratio } } -test "call method on bound fn referring to var instance" { - if (builtin.zig_backend != .stage1) { - // Let's delay solving this one; I want to try to eliminate bound functions from - // the language. - return error.SkipZigTest; // TODO - } - - try expect(bound_fn() == 1237); -} - -const SimpleStruct = struct { - field: i32, - - fn method(self: *const SimpleStruct) i32 { - return self.field + 3; - } -}; - -var simple_struct = SimpleStruct{ .field = 1234 }; - -const bound_fn = simple_struct.method; - test "ptr to local array argument at comptime" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO diff --git a/test/cases/compile_errors/call method on bound fn referring to var instance.zig b/test/cases/compile_errors/call method on bound fn referring to var instance.zig new file mode 100644 index 0000000000..10ff584124 --- /dev/null +++ b/test/cases/compile_errors/call method on bound fn referring to var instance.zig @@ -0,0 +1,20 @@ +export fn entry() void { + bad(bound_fn() == 1237); +} +const SimpleStruct = struct { + field: i32, + + fn method(self: *const SimpleStruct) i32 { + return self.field + 3; + } +}; +var simple_struct = SimpleStruct{ .field = 1234 }; +const bound_fn = simple_struct.method; +fn bad(ok: bool) void { + _ = ok; +} +// error +// target=native +// backend=stage2 +// +// :12:18: error: unable to resolve comptime value