Skip to content

Commit

Permalink
make sure staged function static parameters are bound in the right or…
Browse files Browse the repository at this point in the history
…der (ref JuliaLang#8505)
  • Loading branch information
JeffBezanson committed Oct 26, 2014
1 parent ffebd6a commit b86ff38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,7 @@ static jl_function_t *jl_mt_assoc_by_type(jl_methtable_t *mt, jl_tuple_t *tt, in

while (m != JL_NULL) {
if (m->tvars!=jl_null) {
ti = lookup_match((jl_value_t*)tt, (jl_value_t*)m->sig,
&env, m->tvars);
ti = lookup_match((jl_value_t*)tt, (jl_value_t*)m->sig, &env, m->tvars);
if (ti != (jl_value_t*)jl_bottom_type) {
// parametric methods only match if all typevars are matched by
// non-typevars.
Expand Down
35 changes: 19 additions & 16 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,12 +1464,9 @@ jl_value_t *jl_type_intersection_matching(jl_value_t *a, jl_value_t *b,
}
}

*penv = jl_alloc_tuple_uninit(eqc.n);
for(int i=0; i < eqc.n; i+=2) {
jl_tupleset(*penv, i, eqc.data[i]);
jl_tupleset(*penv, i+1, *tvar_lookup(&eqc, &eqc.data[i+1]));
eqc.data[i+1] = *tvar_lookup(&eqc, &eqc.data[i+1]);
}

if (env0 > 0) {
/*
in a situation like this:
Expand All @@ -1479,27 +1476,33 @@ jl_value_t *jl_type_intersection_matching(jl_value_t *a, jl_value_t *b,
N = 1
So we need to instantiate all the RHS's first.
*/
for(int i=1; i < eqc.n; i+=2) {
jl_value_t *rhs = jl_tupleref(*penv,i);
if (jl_has_typevars_(rhs,1)) {
JL_TRY {
jl_tupleset(*penv, i,
jl_instantiate_type_with(rhs,
&jl_t0(*penv), eqc.n/2));
}
JL_CATCH {
}
for(int i=0; i < eqc.n; i+=2) {
JL_TRY {
eqc.data[i+1] = jl_instantiate_type_with(eqc.data[i+1], eqc.data, eqc.n/2);
}
JL_CATCH {
}
}
JL_TRY {
*pti = (jl_value_t*)jl_instantiate_type_with((jl_value_t*)*pti,
&jl_t0(*penv), eqc.n/2);
*pti = (jl_value_t*)jl_instantiate_type_with(*pti, eqc.data, eqc.n/2);
}
JL_CATCH {
*pti = (jl_value_t*)jl_bottom_type;
}
}

// return environment in same order as tvars
*penv = jl_alloc_tuple_uninit(tvarslen*2);
for(int tk=0; tk < tvarslen; tk++) {
jl_tvar_t *tv = (jl_tvar_t*)tvs[tk];
for(e=0; e < eqc.n; e+=2) {
if (eqc.data[e] == (jl_value_t*)tv) {
jl_tupleset(*penv, tk*2, tv);
jl_tupleset(*penv, tk*2+1, eqc.data[e+1]);
}
}
}

JL_GC_POP();
if (jl_is_typevar(*pti) && !(jl_is_typevar(a) && jl_is_typevar(b)))
return ((jl_tvar_t*)*pti)->ub;
Expand Down
11 changes: 7 additions & 4 deletions test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ end
@test MyTest8497.h(3) == 4

# static parameters (issue #8505)
stagedfunction f8505{T}(x::Vector{T})
T
stagedfunction foo1{N,T}(a::Array{T,N})
"N = $N, T = $T"
end
@test f8505([1.0]) === Float64
@test f8505([1]) === Int
stagedfunction foo2{T,N}(a::Array{T,N})
"N = $N, T = $T"
end
@test foo1(randn(3,3)) == "N = 2, T = Float64"
@test foo2(randn(3,3)) == "N = 2, T = Float64"

0 comments on commit b86ff38

Please sign in to comment.