diff options
| author | Patrick Walton <[email protected]> | 2010-12-10 18:08:32 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2010-12-10 18:08:32 -0800 |
| commit | de118d79b603b84e2911527a586f7716b750c5fa (patch) | |
| tree | 5ade03edc398491cd5a70a449fabf21832b46ab4 /src/comp/middle | |
| parent | rustc: Add update_env_for_arm to fold; we'll need it to resolve pattern bindings (diff) | |
| download | rust-de118d79b603b84e2911527a586f7716b750c5fa.tar.xz rust-de118d79b603b84e2911527a586f7716b750c5fa.zip | |
rustc: Resolve pattern bindings
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/fold.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/resolve.rs | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 54e09838..521b433e 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -574,7 +574,7 @@ fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm { let ENV env_ = fld.update_env_for_arm(env, a); auto ppat = fold_pat(env_, fld, a.pat); auto bblock = fold_block(env_, fld, a.block); - ret rec(pat=ppat, block=bblock); + ret rec(pat=ppat, block=bblock, index=a.index); } fn fold_arg[ENV](&ENV env, ast_fold[ENV] fld, &arg a) -> arg { diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index 491d9e4a..08175e78 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -18,6 +18,7 @@ tag scope { scope_crate(@ast.crate); scope_item(@ast.item); scope_block(ast.block); + scope_arm(ast.arm); } type env = rec(list[scope] scopes, @@ -120,6 +121,15 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] { case (_) { /* fall through */ } } } + + case (scope_arm(?a)) { + alt (a.index.find(i)) { + case (some[ast.def_id](?did)) { + ret some[def](ast.def_binding(did)); + } + case (_) { /* fall through */ } + } + } } ret none[def]; } @@ -189,6 +199,11 @@ fn update_env_for_block(&env e, &ast.block b) -> env { ret rec(scopes = cons[scope](scope_block(b), @e.scopes) with e); } +fn update_env_for_arm(&env e, &ast.arm p) -> env { + log "update_env_for_arm"; + ret rec(scopes = cons[scope](scope_arm(p), @e.scopes) with e); +} + fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate { let fold.ast_fold[env] fld = fold.new_identity_fold[env](); @@ -197,7 +212,8 @@ fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate { fold_ty_path = bind fold_ty_path(_,_,_,_), update_env_for_crate = bind update_env_for_crate(_,_), update_env_for_item = bind update_env_for_item(_,_), - update_env_for_block = bind update_env_for_block(_,_) + update_env_for_block = bind update_env_for_block(_,_), + update_env_for_arm = bind update_env_for_arm(_,_) with *fld ); auto e = rec(scopes = nil[scope], |