lean2/tests/lua/tc8.lua
Leonardo de Moura 16bdc51fc4 refactor(kernel/type_checker): simplify type checker API, and remove add_cnstr_fn
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2014-06-26 13:36:31 -07:00

24 lines
796 B
Lua

local env = environment()
local N = Const("N")
env = add_decl(env, mk_var_decl("N", Type))
env = add_decl(env, mk_var_decl("f", mk_arrow(N, N)))
env = add_decl(env, mk_var_decl("a", N))
local f = Const("f")
local a = Const("a")
local m1 = mk_metavar("m1", mk_metavar("m2", mk_sort(mk_meta_univ("l"))))
local ngen = name_generator("tst")
local tc = type_checker(env, ngen)
assert(tc:num_scopes() == 0)
tc:push()
assert(tc:num_scopes() == 1)
print(tc:check(f(m1)))
assert(tc:next_cnstr())
assert(not tc:next_cnstr())
print(tc:check(f(f(m1))))
assert(not tc:next_cnstr()) -- New constraint is not generated
tc:pop() -- forget that we checked f(m1)
print(tc:check(f(m1)))
-- constraint is generated again
assert(tc:next_cnstr())
assert(not tc:next_cnstr())
check_error(function() tc:pop() end)