Skip to content

Commit

Permalink
Fix reachability analysis for intersection types (#2106)
Browse files Browse the repository at this point in the history
This change fixes a bug where methods on members of intersection types
sometimes weren't being reached.

Closes #2102.
  • Loading branch information
Benoit Vey authored and jemc committed Jul 29, 2017
1 parent f39e13e commit 6b5c665
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/libponyc/reach/reach.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,9 @@ static void add_rmethod_to_subtype(reach_t* r, reach_type_t* t,
static void add_rmethod_to_subtypes(reach_t* r, reach_type_t* t,
reach_method_name_t* n, reach_method_t* m, pass_opt_t* opt, bool internal)
{
bool typeexpr = false;
switch(t->underlying)
{
case TK_UNIONTYPE:
case TK_ISECTTYPE:
typeexpr = true;
// fallthrough

case TK_INTERFACE:
case TK_TRAIT:
{
Expand All @@ -308,16 +303,32 @@ static void add_rmethod_to_subtypes(reach_t* r, reach_type_t* t,

while((t2 = reach_type_cache_next(&t->subtypes, &i)) != NULL)
{
if(!internal && typeexpr)
if(!internal || valid_internal_method_for_type(t2, n->name))
add_rmethod_to_subtype(r, t2, n, m, opt, internal);
}

break;
}

case TK_ISECTTYPE:
{
ast_t* child = ast_child(t->ast_cap);
reach_type_t* t2;

for(; child != NULL; child = ast_sibling(child))
{
if(!internal)
{
ast_t* find = lookup_try(NULL, NULL, t2->ast, n->name);
ast_t* find = lookup_try(NULL, NULL, child, n->name);

if(find == NULL)
continue;

ast_free_unattached(find);
}

t2 = add_type(r, child, opt);

if(!internal || valid_internal_method_for_type(t2, n->name))
add_rmethod_to_subtype(r, t2, n, m, opt, internal);
}
Expand Down

0 comments on commit 6b5c665

Please sign in to comment.