Fix the import handling in "complex" cases. When looking a.b.c and 'a' is a
module, we should look for 'b' *just* in the module 'a' and then continue resolving b.c in the environment created by updating *with* a. Still not 100% correct, but getting there.
This commit is contained in:
parent
c8a2c44a8e
commit
5b9eda4a41
@ -447,6 +447,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
|
||||
import3.rs \
|
||||
import4.rs \
|
||||
import5.rs \
|
||||
import6.rs \
|
||||
item-name-overload.rs \
|
||||
large-records.rs \
|
||||
lazy-init.rs \
|
||||
|
@ -77,6 +77,10 @@ fn lookup_name(&env e, import_map index,
|
||||
// Follow the path of an import and return what it ultimately points to.
|
||||
|
||||
fn find_final_def(&env e, &span sp, vec[ident] idents) -> def_wrap {
|
||||
|
||||
// We are given a series of identifiers (a.b.c.d) and we know that
|
||||
// in the environment 'e' the identifier 'a' was resolved to 'd'. We
|
||||
// should return what a.b.c.d points to in the end.
|
||||
fn found_something(&env e, std.map.hashmap[ast.def_id, bool] pending,
|
||||
&span sp, vec[ident] idents, def_wrap d) -> def_wrap {
|
||||
alt (d) {
|
||||
@ -90,6 +94,7 @@ fn find_final_def(&env e, &span sp, vec[ident] idents) -> def_wrap {
|
||||
}
|
||||
pending.insert(d, true);
|
||||
auto x = inner(e, pending, sp, new_idents);
|
||||
pending.remove(d);
|
||||
ret found_something(e, pending, sp, idents, x);
|
||||
}
|
||||
}
|
||||
@ -103,11 +108,23 @@ fn find_final_def(&env e, &span sp, vec[ident] idents) -> def_wrap {
|
||||
}
|
||||
alt (d) {
|
||||
case (def_wrap_mod(?i)) {
|
||||
auto new_idents = _vec.slice[ident](idents, 1u, len);
|
||||
auto tmp_e = rec(scopes = nil[scope],
|
||||
sess = e.sess);
|
||||
auto new_e = update_env_for_item(tmp_e, i);
|
||||
ret inner(new_e, pending, sp, new_idents);
|
||||
auto rest_idents = _vec.slice[ident](idents, 1u, len);
|
||||
auto empty_e = rec(scopes = nil[scope],
|
||||
sess = e.sess);
|
||||
auto tmp_e = update_env_for_item(empty_e, i);
|
||||
auto next_i = rest_idents.(0);
|
||||
auto next_ = lookup_name_wrapped(tmp_e, next_i);
|
||||
alt (next_) {
|
||||
case (none[def_wrap]) {
|
||||
e.sess.span_err(sp, "unresolved name: " + next_i);
|
||||
fail;
|
||||
}
|
||||
case (some[def_wrap](?next)) {
|
||||
auto combined_e = update_env_for_item(e, i);
|
||||
ret found_something(combined_e, pending, sp,
|
||||
rest_idents, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (def_wrap_use(?c)) {
|
||||
e.sess.span_err(sp, "Crate access is not implemented");
|
||||
|
8
src/test/compile-fail/import4.rs
Normal file
8
src/test/compile-fail/import4.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// error-pattern: recursive import
|
||||
|
||||
import zed.bar;
|
||||
import bar.zed;
|
||||
|
||||
fn main(vec[str] args) {
|
||||
log "loop";
|
||||
}
|
15
src/test/run-pass/import6.rs
Normal file
15
src/test/run-pass/import6.rs
Normal file
@ -0,0 +1,15 @@
|
||||
import bar.baz;
|
||||
import foo.zed;
|
||||
mod foo {
|
||||
mod zed {
|
||||
fn baz() {
|
||||
log "baz";
|
||||
}
|
||||
}
|
||||
}
|
||||
mod bar {
|
||||
import zed.baz;
|
||||
}
|
||||
fn main(vec[str] args) {
|
||||
baz();
|
||||
}
|
Loading…
Reference in New Issue
Block a user