summary refs log tree commit diff
path: root/src/test/run-pass/sendfn-generic-fn.rs
blob: 9e1e5127a2452b561d31023a9bee385aad5c7293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std;

import comm::chan;
import comm::send;

fn main() { test05(); }

type pair<A,B> = { a: A, b: B };

fn make_generic_record<A: copy, B: copy>(a: A, b: B) -> pair<A,B> {
    ret {a: a, b: b};
}

fn test05_start(&&f: fn~(&&float, &&str) -> pair<float, str>) {
    let p = f(22.22f, "Hi");
    log(debug, p);
    assert p.a == 22.22f;
    assert p.b == "Hi";

    let q = f(44.44f, "Ho");
    log(debug, q);
    assert q.a == 44.44f;
    assert q.b == "Ho";
}

fn spawn<A: copy, B: copy>(f: native fn(fn~(A,B)->pair<A,B>)) {
    let arg = fn~(a: A, b: B) -> pair<A,B> {
        ret make_generic_record(a, b);
    };
    task::spawn {|| f(arg); };
}

fn test05() {
    spawn::<float,str>(test05_start);
}