Skip to content

Commit a0ccfec

Browse files
committed
---
yaml --- r: 1291 b: refs/heads/master c: 9e2324a h: refs/heads/master i: 1289: 15911c9 1287: cdab115 v: v3
1 parent d6b204e commit a0ccfec

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 18947f83cce186933f031950b9acdf9d1102e254
2+
refs/heads/master: 9e2324ad1e3f2abf528fbbbdafe2cb8a18c3151d

trunk/src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ TEST_XFAILS_BOOT := $(TASK_XFAILS) \
402402
test/run-pass/vec-slice.rs \
403403
test/run-pass/while-and-do-while.rs \
404404
test/run-fail/task-comm-14.rs \
405+
test/compile-fail/bad-expr-path.rs \
405406
test/compile-fail/import.rs \
406407
test/compile-fail/import2.rs \
407408
test/compile-fail/import3.rs \
@@ -502,6 +503,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
502503
$(addprefix test/compile-fail/, \
503504
arg-count-mismatch.rs \
504505
arg-type-mismatch.rs \
506+
bad-expr-path.rs \
505507
import.rs \
506508
import2.rs \
507509
import3.rs \

trunk/src/comp/middle/resolve.rs

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tag def_wrap {
3535
def_wrap_import(@ast.view_item);
3636
def_wrap_mod(@ast.item);
3737
def_wrap_other(def);
38+
def_wrap_expr_field(ident);
3839
def_wrap_resolving;
3940
}
4041

@@ -88,9 +89,11 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
8889

8990
// Follow the path of an import and return what it ultimately points to.
9091

92+
// If used after imports are resolved, import_id is none.
93+
9194
fn find_final_def(&env e, import_map index,
9295
&span sp, vec[ident] idents,
93-
ast.def_id import_id) -> def_wrap {
96+
option.t[ast.def_id] import_id) -> def_wrap {
9497

9598
// We are given a series of identifiers (a.b.c.d) and we know that
9699
// in the environment 'e' the identifier 'a' was resolved to 'd'. We
@@ -101,7 +104,8 @@ fn find_final_def(&env e, import_map index,
101104
case (def_wrap_import(?imp)) {
102105
alt (imp.node) {
103106
case (ast.view_item_import(?new_idents, ?d, _)) {
104-
auto x = inner(e, index, sp, new_idents, d);
107+
auto x = find_final_def(e, index, sp, new_idents,
108+
some(d));
105109
ret found_something(e, index, sp, idents, x);
106110
}
107111
}
@@ -138,15 +142,14 @@ fn find_final_def(&env e, import_map index,
138142
}
139143
case (_) {
140144
auto first = idents.(0);
141-
e.sess.span_err(sp, first + " is not a module or crate");
145+
ret def_wrap_expr_field(first);
142146
}
143147
}
144148
fail;
145149
}
146150

147-
fn inner(&env e, import_map index, &span sp, vec[ident] idents,
148-
ast.def_id import_id) -> def_wrap {
149-
alt (index.find(import_id)) {
151+
if (import_id != none[ast.def_id]) {
152+
alt (index.find(option.get[ast.def_id](import_id))) {
150153
case (some[def_wrap](?x)) {
151154
alt (x) {
152155
case (def_wrap_resolving) {
@@ -161,22 +164,23 @@ fn find_final_def(&env e, import_map index,
161164
case (none[def_wrap]) {
162165
}
163166
}
164-
auto first = idents.(0);
165-
index.insert(import_id, def_wrap_resolving);
166-
auto d_ = lookup_name_wrapped(e, first);
167-
alt (d_) {
168-
case (none[tup(@env, def_wrap)]) {
169-
e.sess.span_err(sp, "unresolved name: " + first);
170-
fail;
171-
}
172-
case (some[tup(@env, def_wrap)](?d)) {
173-
auto x = found_something(*d._0, index, sp, idents, d._1);
174-
index.insert(import_id, x);
175-
ret x;
167+
index.insert(option.get[ast.def_id](import_id), def_wrap_resolving);
168+
}
169+
auto first = idents.(0);
170+
auto d_ = lookup_name_wrapped(e, first);
171+
alt (d_) {
172+
case (none[tup(@env, def_wrap)]) {
173+
e.sess.span_err(sp, "unresolved name: " + first);
174+
fail;
175+
}
176+
case (some[tup(@env, def_wrap)](?d)) {
177+
auto x = found_something(*d._0, index, sp, idents, d._1);
178+
if (import_id != none[ast.def_id]) {
179+
index.insert(option.get[ast.def_id](import_id), x);
176180
}
181+
ret x;
177182
}
178183
}
179-
ret inner(e, index, sp, idents, import_id);
180184
}
181185

182186
fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
@@ -434,10 +438,13 @@ fn fold_expr_path(&env e, &span sp, &ast.path p, &option.t[def] d,
434438
}
435439
}
436440

437-
// FIXME: once espindola's modifications to lookup land, actually step
438-
// through the path doing speculative lookup, and extend the maximal
439-
// static prefix. For now we are always using the minimal prefix: first
440-
// ident is static anchor, rest turn into fields.
441+
// FIXME: All this call to find_final_def does right now is find
442+
// unresolved names. It should be extended to return a wrapper
443+
// over ast.expr. It is in a perfect position to construct
444+
// the expr_field(expr_field(...(expr_path(...)))) we should return.
445+
446+
auto index = new_def_hash[def_wrap]();
447+
find_final_def(e, index, sp, p.node.idents, none[ast.def_id]);
441448

442449
auto p_ = rec(node=rec(idents = vec(id0) with p.node) with p);
443450
auto ex = @fold.respan[ast.expr_](sp, ast.expr_path(p_, d_, a));
@@ -457,7 +464,14 @@ fn fold_view_item_import(&env e, &span sp,
457464
// Produce errors for invalid imports
458465
auto len = _vec.len[ast.ident](is);
459466
auto last_id = is.(len - 1u);
460-
auto d = find_final_def(e, index, sp, is, id);
467+
auto d = find_final_def(e, index, sp, is, some(id));
468+
alt (d) {
469+
case (def_wrap_expr_field(?ident)) {
470+
e.sess.span_err(sp, ident + " is not a module or crate");
471+
}
472+
case (_) {
473+
}
474+
}
461475
let option.t[def] target_def = some(unwrap_def(d));
462476
ret @fold.respan[ast.view_item_](sp, ast.view_item_import(is, id,
463477
target_def));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// error-pattern: unresolved name: a
2+
3+
mod m1 {
4+
}
5+
6+
fn main(vec[str] args) {
7+
log m1.a;
8+
}

0 commit comments

Comments
 (0)