Skip to content

Commit 7ad5eee

Browse files
committed
fail jl_specializations_lookup more conservatively in the presence of incorrect UnionAll types
previously, inserting a type and then looking up that exact type could fail, since it would compute the UnionAll in the wrong position and thus not consider the types to be equivalent
1 parent 85cf5e6 commit 7ad5eee

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ JL_DLLEXPORT jl_typemap_entry_t *jl_specializations_insert(jl_method_t *m, jl_tu
119119

120120
JL_DLLEXPORT jl_value_t *jl_specializations_lookup(jl_method_t *m, jl_tupletype_t *type)
121121
{
122-
jl_typemap_entry_t *sf = jl_typemap_assoc_by_type(m->specializations, type, NULL, 1, /*subtype*/0, /*offs*/0);
122+
jl_typemap_entry_t *sf = jl_typemap_assoc_by_type(m->specializations, type, NULL, 2, /*subtype*/0, /*offs*/0);
123123
if (!sf)
124124
return jl_nothing;
125125
return sf->func.value;
126126
}
127127

128128
JL_DLLEXPORT jl_value_t *jl_methtable_lookup(jl_methtable_t *mt, jl_tupletype_t *type)
129129
{
130-
jl_typemap_entry_t *sf = jl_typemap_assoc_by_type(mt->defs, type, NULL, 1, /*subtype*/0, /*offs*/0);
130+
jl_typemap_entry_t *sf = jl_typemap_assoc_by_type(mt->defs, type, NULL, 2, /*subtype*/0, /*offs*/0);
131131
if (!sf)
132132
return jl_nothing;
133133
return sf->func.value;

src/typemap.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,11 @@ int jl_typemap_intersection_visitor(union jl_typemap_t map, int offs,
514514

515515
int sigs_eq(jl_value_t *a, jl_value_t *b, int useenv)
516516
{
517-
if (jl_has_typevars(a) || jl_has_typevars(b)) {
518-
return jl_types_equal_generic(a,b,useenv);
517+
// useenv == 0 : subtyping + ensure typevars correspond
518+
// useenv == 1 : subtyping + ensure typevars correspond + fail if bound != bound in some typevar match
519+
// useenv == 2 : ignore typevars (because UnionAll getting lost in intersection can cause jl_types_equal to fail in the wrong direction for some purposes)
520+
if (useenv != 2 && (jl_has_typevars(a) || jl_has_typevars(b))) {
521+
return jl_types_equal_generic(a, b, useenv);
519522
}
520523
return jl_subtype(a, b, 0) && jl_subtype(b, a, 0);
521524
}

0 commit comments

Comments
 (0)