From b4c3b83f26641c3d868e84b991fe88c8c556688c Mon Sep 17 00:00:00 2001 From: Paul Stansifer Date: Wed, 22 Jun 2011 15:41:39 -0700 Subject: [PATCH] Fix bug: globbed imports were importing everything visible from the other module, not just everything exported. --- src/comp/middle/resolve.rs | 4 ++-- src/comp/middle/tstate/auxiliary.rs | 2 ++ src/comp/middle/tstate/collect_locals.rs | 2 +- src/comp/middle/ty.rs | 4 +++- src/comp/pretty/ppaux.rs | 13 +++++++++++-- src/test/compile-fail/import-glob-export.rs | 14 ++++++++++++++ src/test/run-pass/import-glob-circular.rs | 10 +++++----- 7 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/test/compile-fail/import-glob-export.rs diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index 180b422d5e5..26273d18080 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -940,9 +940,9 @@ fn lookup_in_local_mod(&env e, node_id node_id, &span sp, &ident id, } } } - // not local or explicitly imported; try globs: - ret lookup_glob_in_mod(e, info, sp, id, ns, dr); + // not local or explicitly imported; try globs: + ret lookup_glob_in_mod(e, info, sp, id, ns, outside); } fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id, diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index d2b6a249122..d2f068ba5dc 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -1,5 +1,6 @@ import std::bitv; +import std::str; import std::vec; import std::vec::len; import std::vec::grow; @@ -12,6 +13,7 @@ import front::ast; import front::ast::*; import util::common; import util::common::span; +import util::common::spanned; import util::common::respan; import util::common::log_block; import util::common::new_int_hash; diff --git a/src/comp/middle/tstate/collect_locals.rs b/src/comp/middle/tstate/collect_locals.rs index 7e10f9deb8f..03dd4ca231d 100644 --- a/src/comp/middle/tstate/collect_locals.rs +++ b/src/comp/middle/tstate/collect_locals.rs @@ -3,7 +3,7 @@ import std::vec; import std::vec::plus_option; import front::ast; import front::ast::*; -import option::*; +import std::option::*; import middle::walk::walk_crate; import middle::walk::walk_fn; import middle::walk::ast_visitor; diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index a519ac33bd7..a9f23887075 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -96,6 +96,7 @@ export mt; export node_type_table; export pat_node_id; export pat_ty; +export cname; export path_to_str; export rename; export ret_ty_of_fn; @@ -170,6 +171,7 @@ export type_is_tup_like; export type_is_str; export type_owns_heap_mem; export type_param; +export def_to_str; export unify; export variant_info; export walk_ty; @@ -273,7 +275,7 @@ tag sty { type constr_def = spanned[constr_general[uint]]; type constr_general[T] = - rec(path path, vec[@constr_arg_general[T]] args, def_id id); + rec(ast::path path, vec[@constr_arg_general[T]] args, def_id id); // Data structures used in type unification diff --git a/src/comp/pretty/ppaux.rs b/src/comp/pretty/ppaux.rs index fdf2345c6d9..d8be2bf7712 100644 --- a/src/comp/pretty/ppaux.rs +++ b/src/comp/pretty/ppaux.rs @@ -1,13 +1,22 @@ import std::io; +import std::vec; +import std::str; +import std::option; +import std::option::none; +import std::option::some; import middle::ty::*; import front::lexer; +import front::ast; import pp::word; import pp::eof; import pp::zerobreak; import pp::hardbreak; import front::codemap; import front::codemap::codemap; +import util::common::istr; +import util::common::uistr; +import util::common::ty_mach_to_str; fn ty_to_str(&ctxt cx, &t typ) -> str { fn fn_input_to_str(&ctxt cx, &rec(middle::ty::mode mode, t ty) input) -> @@ -123,8 +132,8 @@ fn ty_to_str(&ctxt cx, &t typ) -> str { fn ty_to_short_str(&ctxt cx, t typ) -> str { auto f = def_to_str; - auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata::ac_no_abbrevs); - auto s = metadata::Encode::ty_str(ecx, typ); + auto ecx = @rec(ds=f, tcx=cx, abbrevs=middle::metadata::ac_no_abbrevs); + auto s = middle::metadata::Encode::ty_str(ecx, typ); if (str::byte_len(s) >= 32u) { s = str::substr(s, 0u, 32u); } ret s; } diff --git a/src/test/compile-fail/import-glob-export.rs b/src/test/compile-fail/import-glob-export.rs new file mode 100644 index 00000000000..561d791464c --- /dev/null +++ b/src/test/compile-fail/import-glob-export.rs @@ -0,0 +1,14 @@ + +// error-pattern:unresolved name + +import m1::*; + +mod m1 { + export f1; + fn f1() {} + fn f2() {} +} + +fn main () { + f2(); +} \ No newline at end of file diff --git a/src/test/run-pass/import-glob-circular.rs b/src/test/run-pass/import-glob-circular.rs index 333cde25dd3..45e0dd52e5c 100644 --- a/src/test/run-pass/import-glob-circular.rs +++ b/src/test/run-pass/import-glob-circular.rs @@ -33,8 +33,8 @@ mod test1 { assert(f1() == 1u); //make sure that cached lookups work... assert(f1() == 1u); - assert(f2() == 2u); - assert(f2() == 2u); + //assert(f2() == 2u); //TODO: renable when 'reexport' is implemented + //assert(f2() == 2u); assert(common() == 1u); assert(common() == 1u); } @@ -43,9 +43,9 @@ mod test1 { mod test2 { import circ2::*; fn test2() { - assert(f1() == 1u); - //make sure that cached lookups work... - assert(f1() == 1u); + //assert(f1() == 1u); //TODO: renable when 'reexport' is implemented + ////make sure that cached lookups work... + //assert(f1() == 1u); assert(f2() == 2u); assert(f2() == 2u); assert(common() == 2u);