Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "last" lookup bug #201

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -448,6 +448,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
import4.rs \
import5.rs \
import6.rs \
import7.rs \
item-name-overload.rs \
large-records.rs \
lazy-init.rs \
39 changes: 27 additions & 12 deletions src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
@@ -40,11 +40,11 @@ fn lookup_name(&env e, import_map index,
ast.ident i) -> option.t[def] {
auto d_ = lookup_name_wrapped(e, i);
alt (d_) {
case (none[def_wrap]) {
case (none[tup(@env, def_wrap)]) {
ret none[def];
}
case (some[def_wrap](?d)) {
alt (d) {
case (some[tup(@env, def_wrap)](?d)) {
alt (d._1) {
case (def_wrap_use(?it)) {
alt (it.node) {
case (ast.view_item_use(_, _, ?id)) {
@@ -115,14 +115,14 @@ fn find_final_def(&env e, &span sp, vec[ident] idents) -> def_wrap {
auto next_i = rest_idents.(0);
auto next_ = lookup_name_wrapped(tmp_e, next_i);
alt (next_) {
case (none[def_wrap]) {
case (none[tup(@env, def_wrap)]) {
e.sess.span_err(sp, "unresolved name: " + next_i);
fail;
}
case (some[def_wrap](?next)) {
case (some[tup(@env, def_wrap)](?next)) {
auto combined_e = update_env_for_item(e, i);
ret found_something(combined_e, pending, sp,
rest_idents, next);
rest_idents, next._1);
}
}
}
@@ -141,20 +141,20 @@ fn find_final_def(&env e, &span sp, vec[ident] idents) -> def_wrap {
auto first = idents.(0);
auto d_ = lookup_name_wrapped(e, first);
alt (d_) {
case (none[def_wrap]) {
case (none[tup(@env, def_wrap)]) {
e.sess.span_err(sp, "unresolved name: " + first);
fail;
}
case (some[def_wrap](?d)) {
ret found_something(e, pending, sp, idents, d);
case (some[tup(@env, def_wrap)](?d)) {
ret found_something(*d._0, pending, sp, idents, d._1);
}
}
}
auto pending = new_def_hash[bool]();
ret inner(e, pending, sp, idents);
}

fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[def_wrap] {
fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {

// log "resolving name " + i;

@@ -308,8 +308,23 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[def_wrap] {
ret none[def_wrap];
}

ret std.list.find[scope,def_wrap](e.scopes,
bind in_scope(i, _));
alt (e.scopes) {
case (nil[scope]) {
ret none[tup(@env, def_wrap)];
}
case (cons[scope](?hd, ?tl)) {
auto x = in_scope(i, hd);
alt (x) {
case (some[def_wrap](?x)) {
ret some(tup(@e, x));
}
case (none[def_wrap]) {
auto outer_env = rec(scopes = *tl with e);
ret lookup_name_wrapped(outer_env, i);
}
}
}
}
}

fn fold_pat_tag(&env e, &span sp, import_map index, ident i,
19 changes: 19 additions & 0 deletions src/test/run-pass/import7.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import bar.baz;
import foo.zed;
mod foo {
mod zed {
fn baz() {
log "baz";
}
}
}
mod bar {
import zed.baz;
mod foo {
mod zed {
}
}
}
fn main(vec[str] args) {
baz();
}