Skip to content

Commit 580d527

Browse files
author
Rafael Avila de Espindola
committed
Add missing fold of native functions.
1 parent 3d63aa1 commit 580d527

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/comp/middle/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld,
872872
ret fld.fold_native_item_ty(env_, i.span, ident, id);
873873
}
874874
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) {
875-
ret fld.fold_native_item_fn(env_, i.span, ident, fn_decl,
875+
auto d = fold_fn_decl[ENV](env_, fld, fn_decl);
876+
ret fld.fold_native_item_fn(env_, i.span, ident, d,
876877
ty_params, id);
877878
}
878879
}

src/comp/middle/resolve.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import std._vec;
1818
tag scope {
1919
scope_crate(@ast.crate);
2020
scope_item(@ast.item);
21+
scope_native_item(@ast.native_item);
2122
scope_loop(@ast.decl); // there's only 1 decl per loop.
2223
scope_block(ast.block);
2324
scope_arm(ast.arm);
@@ -309,6 +310,23 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
309310
}
310311
}
311312

313+
fn handle_fn_decl(ast.ident i, &ast.fn_decl decl,
314+
&vec[ast.ty_param] ty_params) -> option.t[def_wrap] {
315+
for (ast.arg a in decl.inputs) {
316+
if (_str.eq(a.ident, i)) {
317+
auto t = ast.def_arg(a.id);
318+
ret some(def_wrap_other(t));
319+
}
320+
}
321+
for (ast.ty_param tp in ty_params) {
322+
if (_str.eq(tp.ident, i)) {
323+
auto t = ast.def_ty_arg(tp.id);
324+
ret some(def_wrap_other(t));
325+
}
326+
}
327+
ret none[def_wrap];
328+
}
329+
312330
fn in_scope(ast.ident i, &scope s) -> option.t[def_wrap] {
313331
alt (s) {
314332

@@ -319,18 +337,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
319337
case (scope_item(?it)) {
320338
alt (it.node) {
321339
case (ast.item_fn(_, ?f, ?ty_params, _, _)) {
322-
for (ast.arg a in f.decl.inputs) {
323-
if (_str.eq(a.ident, i)) {
324-
auto t = ast.def_arg(a.id);
325-
ret some(def_wrap_other(t));
326-
}
327-
}
328-
for (ast.ty_param tp in ty_params) {
329-
if (_str.eq(tp.ident, i)) {
330-
auto t = ast.def_ty_arg(tp.id);
331-
ret some(def_wrap_other(t));
332-
}
333-
}
340+
ret handle_fn_decl(i, f.decl, ty_params);
334341
}
335342
case (ast.item_obj(_, ?ob, ?ty_params, _, _)) {
336343
for (ast.obj_field f in ob.fields) {
@@ -364,6 +371,14 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
364371
}
365372
}
366373

374+
case (scope_native_item(?it)) {
375+
alt (it.node) {
376+
case (ast.native_item_fn(_, ?decl, ?ty_params, _)) {
377+
ret handle_fn_decl(i, decl, ty_params);
378+
}
379+
}
380+
}
381+
367382
case (scope_loop(?d)) {
368383
alt (d.node) {
369384
case (ast.decl_local(?local)) {
@@ -529,6 +544,10 @@ fn update_env_for_item(&env e, @ast.item i) -> env {
529544
ret rec(scopes = cons[scope](scope_item(i), @e.scopes) with e);
530545
}
531546

547+
fn update_env_for_native_item(&env e, @ast.native_item i) -> env {
548+
ret rec(scopes = cons[scope](scope_native_item(i), @e.scopes) with e);
549+
}
550+
532551
fn update_env_for_block(&env e, &ast.block b) -> env {
533552
ret rec(scopes = cons[scope](scope_block(b), @e.scopes) with e);
534553
}
@@ -555,6 +574,8 @@ fn resolve_imports(session.session sess, @ast.crate crate) -> @ast.crate {
555574
= bind fold_view_item_import(_,_,import_index,_,_,_,_),
556575
update_env_for_crate = bind update_env_for_crate(_,_),
557576
update_env_for_item = bind update_env_for_item(_,_),
577+
update_env_for_native_item =
578+
bind update_env_for_native_item(_,_),
558579
update_env_for_block = bind update_env_for_block(_,_),
559580
update_env_for_arm = bind update_env_for_arm(_,_),
560581
update_env_for_expr = bind update_env_for_expr(_,_)
@@ -577,6 +598,8 @@ fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate {
577598
fold_ty_path = bind fold_ty_path(_,_,_,_),
578599
update_env_for_crate = bind update_env_for_crate(_,_),
579600
update_env_for_item = bind update_env_for_item(_,_),
601+
update_env_for_native_item =
602+
bind update_env_for_native_item(_,_),
580603
update_env_for_block = bind update_env_for_block(_,_),
581604
update_env_for_arm = bind update_env_for_arm(_,_),
582605
update_env_for_expr = bind update_env_for_expr(_,_)

0 commit comments

Comments
 (0)