local env = environment() env = begin_namespace_scope(env, "foo") assert(get_namespace(env) == name("foo")) env = add_decl(env, mk_var_decl(name(get_namespace(env), "nat"), Type)) env = add_decl(env, mk_var_decl(name(get_namespace(env), "int"), Type)) env = begin_namespace_scope(env, "bar") assert(get_namespace(env) == name("foo", "bar")) assert(find_decl(env, "int"):name() == name("foo", "int")) assert(find_decl(env, "nat"):name() == name("foo", "nat")) env = add_decl(env, mk_var_decl(name(get_namespace(env), "int"), Type)) assert(find_decl(env, "int"):name() == name("foo", "bar", "int")) assert(get_name_in_namespace(env, name("foo", "bar", "int")) == name("int")) assert(get_name_in_namespace(env, name("foo", "int")) == name("foo", "int")) -- it was shadowed by foo.bar.int assert(get_name_in_namespace(env, name("foo", "nat")) == name("nat")) env = end_scope(env) assert(get_namespace(env) == name("foo")) assert(get_name_in_namespace(env, name("foo", "bar", "int")) == name("bar", "int")) assert(get_name_in_namespace(env, name("foo", "nat")) == name("nat")) env = end_scope(env) assert(get_name_in_namespace(env, name("foo", "bar", "int")) == name("foo", "bar", "int")) assert(get_name_in_namespace(env, name("foo", "nat")) == name("foo", "nat")) check_error(function() env = end_scope(env) end) assert(get_namespace(env) == name())