Skip to content

Commit 2986ed4

Browse files
committed
rustc: Substitute type parameters in type_of_variant(). Add a test case.
1 parent 9aa2690 commit 2986ed4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/comp/middle/trans.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1699,11 +1699,15 @@ fn variant_types(@crate_ctxt cx, &ast.variant v) -> vec[@ty.t] {
16991699
ret tys;
17001700
}
17011701

1702-
fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef {
1702+
fn type_of_variant(@crate_ctxt cx,
1703+
&ast.variant v,
1704+
vec[ast.ty_param] ty_params,
1705+
vec[@ty.t] ty_param_substs) -> TypeRef {
17031706
let vec[TypeRef] lltys = vec();
17041707
auto tys = variant_types(cx, v);
17051708
for (@ty.t typ in tys) {
1706-
lltys += vec(type_of(cx, typ));
1709+
auto typ2 = ty.substitute_ty_params(ty_params, ty_param_substs, typ);
1710+
lltys += vec(type_of(cx, typ2));
17071711
}
17081712
ret T_struct(lltys);
17091713
}
@@ -1850,6 +1854,8 @@ fn iter_structural_ty_full(@block_ctxt cx,
18501854

18511855
auto next_cx = new_sub_block_ctxt(bcx, "tag-iter-next");
18521856

1857+
auto ty_params = tag_ty_params(bcx.fcx.ccx, tid);
1858+
18531859
auto i = 0u;
18541860
for (ast.variant variant in variants) {
18551861
auto variant_cx = new_sub_block_ctxt(bcx,
@@ -1859,7 +1865,8 @@ fn iter_structural_ty_full(@block_ctxt cx,
18591865

18601866
if (_vec.len[ast.variant_arg](variant.args) > 0u) {
18611867
// N-ary variant.
1862-
auto llvarty = type_of_variant(bcx.fcx.ccx, variants.(i));
1868+
auto llvarty = type_of_variant(bcx.fcx.ccx, variants.(i),
1869+
ty_params, tps);
18631870

18641871
auto fn_ty = ty.ann_to_type(variants.(i).ann);
18651872
alt (fn_ty.struct) {
@@ -1870,8 +1877,6 @@ fn iter_structural_ty_full(@block_ctxt cx,
18701877
auto llvarp_b = variant_cx.build.
18711878
TruncOrBitCast(llunion_b_ptr, T_ptr(llvarty));
18721879

1873-
auto ty_params = tag_ty_params(bcx.fcx.ccx, tid);
1874-
18751880
auto j = 0u;
18761881
for (ty.arg a in args) {
18771882
auto v = vec(C_int(0), C_int(j as int));
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tag clam[T] {
2+
a(T);
3+
}
4+
5+
fn main() {
6+
auto c = a(3);
7+
}
8+

0 commit comments

Comments
 (0)