Skip to content

Commit 558a525

Browse files
brsongraydon
authored andcommitted
---
yaml --- r: 1905 b: refs/heads/master c: 8f2a97a h: refs/heads/master i: 1903: 841bef3 v: v3
1 parent eaca1c9 commit 558a525

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 38d54535840603b131cfac0aafc4133e62a7fb56
2+
refs/heads/master: 8f2a97a562916a882ec0818e6295d41971aad5f1

trunk/src/comp/middle/trans.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,11 +3046,14 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
30463046

30473047
// If we have an else expression, then the entire
30483048
// if expression can have a non-nil type.
3049-
// FIXME: Handle dynamic type sizes
30503049
auto expr_ty = ty.expr_ty(elexpr);
3051-
expr_llty = type_of(else_res.bcx.fcx.ccx, expr_ty);
3052-
if (ty.type_is_structural(expr_ty)) {
3053-
expr_llty = T_ptr(expr_llty);
3050+
if (ty.type_has_dynamic_size(expr_ty)) {
3051+
expr_llty = T_typaram_ptr(cx.fcx.ccx.tn);
3052+
} else {
3053+
expr_llty = type_of(else_res.bcx.fcx.ccx, expr_ty);
3054+
if (ty.type_is_structural(expr_ty)) {
3055+
expr_llty = T_ptr(expr_llty);
3056+
}
30543057
}
30553058
}
30563059
case (_) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// xfail-boot
2+
// xfail-stage0
3+
// -*- rust -*-
4+
5+
// Tests for if as expressions with dynamic type sizes
6+
7+
type compare[T] = fn(&T t1, &T t2) -> bool;
8+
9+
fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) {
10+
let T actual = if (true) { expected } else { not_expected };
11+
check (eq(expected, actual));
12+
}
13+
14+
fn test_bool() {
15+
fn compare_bool(&bool b1, &bool b2) -> bool {
16+
ret b1 == b2;
17+
}
18+
auto eq = bind compare_bool(_, _);
19+
test_generic[bool](true, false, eq);
20+
}
21+
22+
fn test_tup() {
23+
type t = tup(int, int);
24+
fn compare_tup(&t t1, &t t2) -> bool {
25+
ret t1 == t2;
26+
}
27+
auto eq = bind compare_tup(_, _);
28+
test_generic[t](tup(1, 2), tup(2, 3), eq);
29+
}
30+
31+
fn test_vec() {
32+
fn compare_vec(&vec[int] v1, &vec[int] v2) -> bool {
33+
ret v1 == v2;
34+
}
35+
auto eq = bind compare_vec(_, _);
36+
test_generic[vec[int]](vec(1, 2), vec(2, 3), eq);
37+
}
38+
39+
fn test_box() {
40+
fn compare_box(&@bool b1, &@bool b2) -> bool {
41+
ret *b1 == *b2;
42+
}
43+
auto eq = bind compare_box(_, _);
44+
test_generic[@bool](@true, @false, eq);
45+
}
46+
47+
fn main() {
48+
test_bool();
49+
test_tup();
50+
// FIXME: These two don't pass yet
51+
test_vec();
52+
test_box();
53+
}

0 commit comments

Comments
 (0)