Skip to content

Commit 8b00ab1

Browse files
committed
Feed the correct return type to the typechecker when typechecking objects, and add a testcase.
1 parent aa37b8c commit 8b00ab1

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

Diff for: src/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
437437
obj-drop.rs \
438438
obj-dtor.rs \
439439
obj-recursion.rs \
440+
obj-return-polytypes.rs \
440441
obj-with-vec.rs \
441442
opeq.rs \
442443
output-slot-variants.rs \

Diff for: src/boot/me/type.ml

+24-14
Original file line numberDiff line numberDiff line change
@@ -845,20 +845,24 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
845845
Stack.push fn_ctx fn_ctx_stack
846846
in
847847

848+
let push_fn_ctx_of_ty_fn (ty_fn:Ast.ty_fn) : unit =
849+
let (ty_sig, ty_fn_aux) = ty_fn in
850+
let ret_ty = ty_sig.Ast.sig_output_slot.Ast.slot_ty in
851+
let is_iter = ty_fn_aux.Ast.fn_is_iter in
852+
push_fn_ctx (Common.option_get ret_ty) is_iter
853+
in
854+
848855
let visit_mod_item_pre _ _ item =
849-
match item.Common.node.Ast.decl_item with
856+
let { Common.node = item; Common.id = item_id } = item in
857+
match item.Ast.decl_item with
850858
Ast.MOD_ITEM_fn _ ->
851-
let id = item.Common.id in
859+
let fn_ty = Hashtbl.find cx.Semant.ctxt_all_item_types item_id in
852860
begin
853-
match Hashtbl.find cx.Semant.ctxt_all_item_types id with
854-
Ast.TY_fn (ty_sig, ty_fn_aux) ->
855-
let ret_ty = ty_sig.Ast.sig_output_slot.Ast.slot_ty in
856-
let is_iter = ty_fn_aux.Ast.fn_is_iter in
857-
push_fn_ctx (Common.option_get ret_ty) is_iter
861+
match fn_ty with
862+
Ast.TY_fn ty_fn -> push_fn_ctx_of_ty_fn ty_fn
858863
| _ ->
859-
Common.bug
860-
()
861-
"Type.visit_mod_item_pre: fn item doesn't have a fn type"
864+
Common.bug ()
865+
"Type.visit_mod_item_pre: fn item didn't have a fn type"
862866
end
863867
| _ -> ()
864868
in
@@ -869,10 +873,16 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
869873
| _ -> ()
870874
in
871875

872-
let visit_obj_fn_pre _ _ fn =
873-
let fn = fn.Common.node in
874-
let ret_ty = fn.Ast.fn_output_slot.Common.node.Ast.slot_ty in
875-
push_fn_ctx (Common.option_get ret_ty) fn.Ast.fn_aux.Ast.fn_is_iter
876+
let visit_obj_fn_pre obj ident _ =
877+
let obj_ty = Hashtbl.find cx.Semant.ctxt_all_item_types obj.Common.id in
878+
match obj_ty with
879+
Ast.TY_fn ({ Ast.sig_output_slot =
880+
{ Ast.slot_ty = Some (Ast.TY_obj (_, methods)) } }, _) ->
881+
push_fn_ctx_of_ty_fn (Hashtbl.find methods ident)
882+
| _ ->
883+
Common.bug ()
884+
"Type.visit_obj_fn_pre: item doesn't have an object type (%a)"
885+
Ast.sprintf_ty obj_ty
876886
in
877887
let visit_obj_fn_post _ _ _ = ignore (Stack.pop fn_ctx_stack) in
878888

Diff for: src/test/run-pass/obj-return-polytypes.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// -*- rust -*-
2+
3+
type clam[T] = tag(signed(int), unsigned(uint));
4+
5+
fn getclam[T]() -> clam[T] {
6+
ret signed[T](42);
7+
}
8+
9+
obj impatience[T]() {
10+
fn moreclam() -> clam[T] {
11+
be getclam[T]();
12+
}
13+
}
14+
15+
fn main() {}
16+

0 commit comments

Comments
 (0)