diff --git a/src/builtins/bindings.zig b/src/builtins/bindings.zig index 777157f70..127d72713 100644 --- a/src/builtins/bindings.zig +++ b/src/builtins/bindings.zig @@ -75,19 +75,7 @@ pub const Symbol = enum { paused, done, - @"error", float, - object, - map, - list, - function, - fiber, - string, - array, - none, - symbol, - pointer, - metatype, // Open modes. read, diff --git a/src/parser.zig b/src/parser.zig index 3c5b099f2..9fb0dd65d 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -900,7 +900,7 @@ pub const Parser = struct { .pound, .void_k, .type_k, - .none_k, + .error_k, .ident => { return try self.parseTermExpr(.{}); }, diff --git a/src/std/test.cy b/src/std/test.cy index 8ce9baa8d..331974f6e 100644 --- a/src/std/test.cy +++ b/src/std/test.cy @@ -12,4 +12,17 @@ --| Returns `true` if two numbers are near each other within epsilon 1e-5. #host func eqNear(a any, b any) bool -#host func fail() any \ No newline at end of file +func fail(): + throw error.AssertError + +func fail(msg String): + eprint(msg) + throw error.AssertError + +--| Asserts that an error was thrown when invoking a function. +func throws(fn any, err error): + var res = try fn() + if typeof(res) != error: + fail('Expected error.') + if res != err: + fail("Expected `$(err)`, found `$(res)`.") \ No newline at end of file diff --git a/src/std/test.zig b/src/std/test.zig index c46746548..13ea061ba 100644 --- a/src/std/test.zig +++ b/src/std/test.zig @@ -35,7 +35,6 @@ const funcs = [_]NameHostFunc{ .{"eq", eq}, .{"eqList", zErrFunc(eqList)}, .{"eqNear", zErrFunc(eqNear)}, - .{"fail", fail}, }; pub fn onLoad(vm_: ?*cc.VM, mod: cc.Sym) callconv(.C) void { @@ -46,10 +45,6 @@ pub fn onLoad(vm_: ?*cc.VM, mod: cc.Sym) callconv(.C) void { b.declareFuncSig("erase", &.{bt.Any}, bt.Dynamic, erase) catch cy.fatal(); } -fn fail(vm: *cy.VM, _: [*]const Value, _: u8) Value { - return rt.prepThrowError(vm, .AssertError); -} - /// Simply returns the value so the caller get's an erased `any` type. fn erase(vm: *cy.VM, args: [*]const Value, _: u8) Value { vm.retain(args[0]); diff --git a/test/core/symbols.cy b/test/core/symbols.cy index 0c5d92d87..435aabdf8 100644 --- a/test/core/symbols.cy +++ b/test/core/symbols.cy @@ -1,6 +1,6 @@ use test var n = .Tiger -test.eq(int(n), 63) +test.eq(int(n), 53) --cytest: pass \ No newline at end of file