feat(frontends/lean/parser): protect imported modules from Lua definitions and macros in the file importing the module

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-12-26 13:21:36 -08:00
parent ba02132a90
commit 8e4560a866
5 changed files with 23 additions and 1 deletions

View file

@ -2346,7 +2346,8 @@ class parser::imp {
return;
}
try {
parser import_parser(m_env, m_io_state, in, m_script_state, true /* use exceptions */, false /* not interactive */);
script_state state; // Empty state object for the imported module
parser import_parser(m_env, m_io_state, in, &state, true /* use exceptions */, false /* not interactive */);
import_parser();
} catch (interrupted &) {
throw;

11
tests/lean/macro.lean Normal file
View file

@ -0,0 +1,11 @@
(**
macro("IdMacro",
{ macro_arg.Expr },
function (env, e)
return e
end
)
**)
Show IdMacro 10.
Import "module.lean"

View file

@ -0,0 +1,5 @@
Set: pp::colors
Set: pp::unicode
10
Error (line: 2, pos: 5) unknown identifier 'IdMacro'
Error (line: 11, pos: 0) failed to import file './module.lean'

2
tests/lean/module.lean Normal file
View file

@ -0,0 +1,2 @@
(* The following command should fail because the IdMacro is not defined *)
Show IdMacro 20.

View file

@ -0,0 +1,3 @@
Set: pp::colors
Set: pp::unicode
Error (line: 2, pos: 5) unknown identifier 'IdMacro'