fix(library/choice): avoid assertion violation when Lua API is misused
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
3169f8c126
commit
2c0f596665
2 changed files with 11 additions and 3 deletions
|
@ -10,6 +10,8 @@ Author: Leonardo de Moura
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
static name g_choice_name("choice");
|
static name g_choice_name("choice");
|
||||||
|
[[ noreturn ]] static void throw_ex() { throw exception("unexpected occurrence of 'choice' expression"); }
|
||||||
|
|
||||||
// We encode a 'choice' expression using a macro.
|
// We encode a 'choice' expression using a macro.
|
||||||
// This is a trick to avoid creating a new kind of expression.
|
// This is a trick to avoid creating a new kind of expression.
|
||||||
// 'Choice' expressions are temporary objects used by the elaborator,
|
// 'Choice' expressions are temporary objects used by the elaborator,
|
||||||
|
@ -19,9 +21,9 @@ public:
|
||||||
virtual name get_name() const { return g_choice_name; }
|
virtual name get_name() const { return g_choice_name; }
|
||||||
// Choice expressions must be replaced with metavariables before invoking the type checker.
|
// Choice expressions must be replaced with metavariables before invoking the type checker.
|
||||||
// Choice expressions cannot be exported. They are transient/auxiliary objects.
|
// Choice expressions cannot be exported. They are transient/auxiliary objects.
|
||||||
virtual expr get_type(expr const &, expr const *, extension_context &) const { lean_unreachable(); }
|
virtual expr get_type(expr const &, expr const *, extension_context &) const { throw_ex(); }
|
||||||
virtual optional<expr> expand(expr const &, extension_context &) const { lean_unreachable(); }
|
virtual optional<expr> expand(expr const &, extension_context &) const { throw_ex(); }
|
||||||
virtual void write(serializer &) const { lean_unreachable(); }
|
virtual void write(serializer &) const { throw_ex(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static macro_definition g_choice(new choice_macro_cell());
|
static macro_definition g_choice(new choice_macro_cell());
|
||||||
|
|
6
tests/lua/choice2.lua
Normal file
6
tests/lua/choice2.lua
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
local a = Local("a", Bool)
|
||||||
|
local b = Local("b", Bool)
|
||||||
|
local c = mk_choice(a, b)
|
||||||
|
print(c)
|
||||||
|
local env = environment()
|
||||||
|
check_error(function() env:infer_type(c) end)
|
Loading…
Reference in a new issue