rustboot: Emit an error instead of asserting in trans when a T is passed by value

This commit is contained in:
Patrick Walton 2010-10-28 15:02:00 -07:00
parent b914e0e74c
commit 67bcc70754
11 changed files with 36 additions and 17 deletions

View File

@ -1308,6 +1308,23 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
Common.err (Some item_id) "this function must return a value"
in
let check_fn_ty_validity item_id (ty_sig, _) =
let check_input_slot i slot =
match slot with
{
Ast.slot_ty = Some (Ast.TY_param _);
Ast.slot_mode = Ast.MODE_local
} ->
Common.err
(Some item_id)
"parameter %d of this type-parametric function must be \
passed by reference, not by value"
(i + 1)
| _ -> ()
in
Array.iteri check_input_slot ty_sig.Ast.sig_input_slots
in
let visit_mod_item_pre _ _ item =
let { Common.node = item; Common.id = item_id } = item in
match item.Ast.decl_item with
@ -1316,7 +1333,9 @@ let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
let fn_ty = Hashtbl.find cx.Semant.ctxt_all_item_types item_id in
begin
match fn_ty with
Ast.TY_fn ty_fn -> push_fn_ctx_of_ty_fn ty_fn
Ast.TY_fn ty_fn ->
check_fn_ty_validity item_id ty_fn;
push_fn_ctx_of_ty_fn ty_fn
| _ ->
Common.bug ()
"Type.visit_mod_item_pre: fn item didn't have a fn type"

View File

@ -12,7 +12,7 @@ tag list[T] {
nil;
}
fn foldl[T,U](&list[T] ls, U u, fn(&T t, U u) -> U f) -> U {
fn foldl[T,U](&list[T] ls, &U u, fn(&T t, U u) -> U f) -> U {
alt(ls) {
case (cons[T](?hd, ?tl)) {
auto u_ = f(hd, u);

View File

@ -1,5 +1,5 @@
fn f[T](@int i, T t) {}
fn f[T](@int i, &T t) {}
fn main() {
auto x = bind f[char](@0xdeafbeef, _);
}
}

View File

@ -1,8 +1,8 @@
fn id[T](T t) -> T {
fn id[T](&T t) -> T {
ret t;
}
fn main() {
auto f = bind id[int](_);
check (f(10) == 10);
}
}

View File

@ -1,8 +1,8 @@
fn g[X](X x) -> X {
fn g[X](&X x) -> X {
ret x;
}
fn f[T](T t) -> tup(T,T) {
fn f[T](&T t) -> tup(T,T) {
type pair = tup(T,T);
let pair x = tup(t,t);
ret g[pair](x);

View File

@ -1,4 +1,4 @@
fn f[T](T t) {
fn f[T](&T t) {
log "dropping";
}
@ -6,4 +6,4 @@ fn main() {
type r = rec(@int x, @int y);
auto x = rec(x=@10, y=@12);
f[r](x);
}
}

View File

@ -1,8 +1,8 @@
type tupbox[T] = tup(@T);
type recbox[T] = rec(@T x);
fn tuplift[T](T t) -> tupbox[T] { ret tup(@t); }
fn reclift[T](T t) -> recbox[T] { ret rec(x=@t); }
fn tuplift[T](&T t) -> tupbox[T] { ret tup(@t); }
fn reclift[T](&T t) -> recbox[T] { ret rec(x=@t); }
fn main() {
let int foo = 17;

View File

@ -1,6 +1,6 @@
// -*- rust -*-
fn id[T](T x) -> T {
fn id[T](&T x) -> T {
ret x;
}

View File

@ -4,7 +4,7 @@ iter i() -> () {
put ();
}
fn foo[T](T t) {
fn foo[T](&T t) {
let int x = 10;
for each (() j in i()) {
log x;

View File

@ -1,7 +1,7 @@
fn leaky[T](T t) {
fn leaky[T](&T t) {
}
fn main() {
auto x = @10;
leaky[@int](x);
}
}

View File

@ -92,7 +92,7 @@ fn test_boxes(@int a, @int b, @int c, @int d) {
type eqfn[T] = fn(T a, T b) -> bool;
fn test_parameterized[T](eqfn[T] e, T a, T b, T c, T d) {
fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) {
let deque.t[T] deq = deque.create[T]();
check (deq.size() == 0u);
deq.add_front(a);