forked from ponylang/ponyc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subtypes to unions/isects in the reach pass
This change ensures that unions and intersections pick up their subtypes during the reachability analysis. Closes ponylang#1474.
- Loading branch information
Benoit Vey
committed
Feb 15, 2017
1 parent
ab41349
commit 969c9de
Showing
3 changed files
with
94 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <gtest/gtest.h> | ||
#include <platform.h> | ||
|
||
#include <reach/reach.h> | ||
|
||
#include "util.h" | ||
|
||
|
||
#define TEST_COMPILE(src) DO(test_compile(src, "reach")) | ||
|
||
|
||
class ReachTest : public PassTest | ||
{}; | ||
|
||
|
||
TEST_F(ReachTest, IsectHasSubtypes) | ||
{ | ||
const char* src = | ||
"trait TA\n" | ||
" fun a() => None\n" | ||
|
||
"trait TB\n" | ||
" fun b() => None\n" | ||
|
||
"actor Main is (TA & TB)\n" | ||
" new create(env: Env) =>\n" | ||
" let ab: (TA & TB) = this\n" | ||
" ab.a()\n" | ||
" ab.b()"; | ||
|
||
TEST_COMPILE(src); | ||
|
||
ast_t* ab_ast = type_of("ab"); | ||
ASSERT_NE(ab_ast, (void*)NULL); | ||
|
||
reach_t* reach = compile->reach; | ||
reach_type_t* ab_reach = reach_type(reach, ab_ast); | ||
ASSERT_NE(ab_reach, (void*)NULL); | ||
|
||
size_t i = HASHMAP_BEGIN; | ||
reach_type_t* subtype; | ||
|
||
bool found = false; | ||
while((subtype = reach_type_cache_next(&ab_reach->subtypes, &i)) != NULL) | ||
{ | ||
if(subtype->name == stringtab("Main")) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
ASSERT_TRUE(found); | ||
} |