@@ -2383,38 +2383,52 @@ fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
2383
2383
ret @fold. respan[ ast. item_] ( sp, item) ;
2384
2384
}
2385
2385
2386
- fn check_fn( & @crate_ctxt ccx, & span sp , ast. ident ident , & ast . _fn f ,
2387
- vec[ ast. ty_param ] ty_params , ast . def_id id ,
2388
- ast. ann ann ) -> @ ast. item {
2386
+ fn check_fn( & @crate_ctxt ccx, ast. effect effect ,
2387
+ vec[ ast. arg ] inputs ,
2388
+ @ ast. ty output , & ast . block body ) -> ast. _fn {
2389
2389
auto local_ty_table = @common. new_def_hash[ @ty] ( ) ;
2390
2390
2391
2391
// FIXME: duplicate work: the item annotation already has the arg types
2392
2392
// and return type translated to typeck.ty values. We don't need do to it
2393
2393
// again here, we can extract them.
2394
2394
2395
2395
// Store the type of each argument in the table.
2396
- let vec[ arg] inputs = vec( ) ;
2397
- for ( ast. arg arg in f. inputs) {
2396
+ for ( ast. arg arg in inputs) {
2398
2397
auto input_ty = ast_ty_to_ty_crate( ccx, arg. ty) ;
2399
- inputs += vec( rec( mode=arg. mode, ty=input_ty) ) ;
2400
2398
local_ty_table. insert( arg. id, input_ty) ;
2401
2399
}
2402
-
2403
- auto output_ty = ast_ty_to_ty_crate( ccx, f. output) ;
2404
- auto fn_sty = ty_fn( inputs, output_ty) ;
2405
- auto fn_ann = ast. ann_type( plain_ty( fn_sty) ) ;
2406
-
2407
- let fn_ctxt fcx = rec( ret_ty = output_ty,
2400
+ let fn_ctxt fcx = rec( ret_ty = ast_ty_to_ty_crate( ccx, output) ,
2408
2401
locals = local_ty_table,
2409
2402
ccx = ccx) ;
2410
2403
2411
2404
// TODO: Make sure the type of the block agrees with the function type.
2412
- auto block_t = check_block( fcx, f . body) ;
2405
+ auto block_t = check_block( fcx, body) ;
2413
2406
auto block_wb = writeback( fcx, block_t) ;
2414
2407
2415
- auto fn_t = rec( effect=f . effect, inputs=f . inputs, output=f . output,
2408
+ auto fn_t = rec( effect=effect, inputs=inputs, output=output,
2416
2409
body=block_wb) ;
2417
- auto item = ast. item_fn( ident, fn_t, ty_params, id, fn_ann) ;
2410
+ ret fn_t;
2411
+ }
2412
+
2413
+ fn check_item_fn( & @crate_ctxt ccx, & span sp, ast. ident ident, & ast. _fn f,
2414
+ vec[ ast. ty_param] ty_params, ast. def_id id,
2415
+ ast. ann ann) -> @ast. item {
2416
+
2417
+ // FIXME: duplicate work: the item annotation already has the arg types
2418
+ // and return type translated to typeck.ty values. We don't need do to it
2419
+ // again here, we can extract them.
2420
+
2421
+ let vec[ arg] inputs = vec( ) ;
2422
+ for ( ast. arg arg in f. inputs) {
2423
+ auto input_ty = ast_ty_to_ty_crate( ccx, arg. ty) ;
2424
+ inputs += vec( rec( mode=arg. mode, ty=input_ty) ) ;
2425
+ }
2426
+
2427
+ auto output_ty = ast_ty_to_ty_crate( ccx, f. output) ;
2428
+ auto fn_sty = ty_fn( inputs, output_ty) ;
2429
+ auto fn_ann = ast. ann_type( plain_ty( fn_sty) ) ;
2430
+
2431
+ auto item = ast. item_fn( ident, f, ty_params, id, fn_ann) ;
2418
2432
ret @fold. respan[ ast. item_] ( sp, item) ;
2419
2433
}
2420
2434
@@ -2424,8 +2438,10 @@ fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {
2424
2438
auto ccx = @rec( sess=sess, item_types=result. _1, mutable next_var_id=0 ) ;
2425
2439
2426
2440
auto fld = fold. new_identity_fold[ @crate_ctxt] ( ) ;
2427
- auto f = check_fn; // FIXME: trans_const_lval bug
2428
- fld = @rec( fold_item_fn = f with * fld) ;
2441
+
2442
+ fld = @rec( fold_fn = bind check_fn( _, _, _, _, _) ,
2443
+ fold_item_fn = bind check_item_fn( _, _, _, _, _, _, _)
2444
+ with * fld) ;
2429
2445
ret fold. fold_crate[ @crate_ctxt] ( ccx, fld, result. _0) ;
2430
2446
}
2431
2447
0 commit comments