about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <respindola@mozilla.com>2011-01-14 17:20:14 -0500
committerRafael Ávila de Espíndola <respindola@mozilla.com>2011-01-14 17:34:00 -0500
commit5b9eda4a41a410ffd8529a80c19f499ff856e07f (patch)
tree8643c5269b17344e41e66f1ee7658c39ebc2aa7d /src/comp
parentc8a2c44a8e67d05204bac2850852f7fec0d23332 (diff)
downloadrust-5b9eda4a41a410ffd8529a80c19f499ff856e07f.tar.gz
rust-5b9eda4a41a410ffd8529a80c19f499ff856e07f.zip
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.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/resolve.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs
index a318c779547..a8cbc468237 100644
--- a/src/comp/middle/resolve.rs
+++ b/src/comp/middle/resolve.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");