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.
- Loading branch information
Showing
4 changed files
with
278 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
#include <gtest/gtest.h> | ||
#include <platform.h> | ||
|
||
#include "util.h" | ||
|
||
|
||
#define TEST_COMPILE(src) DO(test_compile(src, "expr")) | ||
#define TEST_ERRORS_1(src, err1) DO(test_errors_1(src, "expr", err1)); | ||
|
||
|
||
class RecoverTest : public PassTest | ||
{}; | ||
|
||
|
||
TEST_F(RecoverTest, CanRecover_NewRefToIso) | ||
{ | ||
const char* src = | ||
"class Class\n" | ||
" new ref create() => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Class iso =>\n" | ||
" recover iso Class end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CanRecover_NewRefToVal) | ||
{ | ||
const char* src = | ||
"class Class\n" | ||
" new ref create() => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Class val =>\n" | ||
" recover val Class end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CantRecover_NewValToIso) | ||
{ | ||
const char* src = | ||
"class Class\n" | ||
" new val create() => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Class iso =>\n" | ||
" recover iso Class end"; | ||
|
||
TEST_ERRORS_1(src, "can't recover to this capability"); | ||
} | ||
|
||
TEST_F(RecoverTest, CantRecover_NewTagToVal) | ||
{ | ||
const char* src = | ||
"class Class\n" | ||
" new tag create() => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Class val =>\n" | ||
" recover val Class end"; | ||
|
||
TEST_ERRORS_1(src, "can't recover to this capability"); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_LetLocalRef) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" let inner: Inner ref = Inner\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_ERRORS_1(src, "can't access a non-sendable local defined outside"); | ||
} | ||
|
||
TEST_F(RecoverTest, CanAccess_LetLocalVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" let inner: Inner val = Inner\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CanAccess_LetLocalConsumedIso) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" let inner: Inner iso = Inner\n" | ||
" recover Wrap(consume inner) end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_VarLocalRef) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" var inner: Inner ref = Inner\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_ERRORS_1(src, "can't access a non-sendable local defined outside"); | ||
} | ||
|
||
TEST_F(RecoverTest, CanAccess_VarLocalVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" var inner: Inner val = Inner\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CanAccess_VarLocalConsumedIso) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" var inner: Inner iso = Inner\n" | ||
" recover Wrap(consume inner) end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_ParamRef) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(inner: Inner ref): Wrap iso =>\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_ERRORS_1(src, "can't access a non-sendable parameter"); | ||
} | ||
|
||
TEST_F(RecoverTest, CanAccess_ParamVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(inner: Inner val): Wrap iso =>\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CanAccess_ParamConsumedIso) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"primitive Prim\n" | ||
" fun apply(inner: Inner iso): Wrap iso =>\n" | ||
" recover Wrap(consume inner) end"; | ||
|
||
TEST_COMPILE(src); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_LetFieldVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"class Class\n" | ||
" let inner: Inner val = Inner\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_ERRORS_1(src, "can't read a field through Class tag"); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_VarFieldVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"class Class\n" | ||
" var inner: Inner val = Inner\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_ERRORS_1(src, "can't read a field through Class tag"); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_EmbedFieldVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"class Class\n" | ||
" embed inner: Inner val = Inner\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" recover Wrap(inner) end"; | ||
|
||
TEST_ERRORS_1(src, "can't read a field through Class tag"); | ||
} | ||
|
||
TEST_F(RecoverTest, CantAccess_FunReturnVal) | ||
{ | ||
const char* src = | ||
"class Inner\n" | ||
"class Wrap\n" | ||
" new create(s: Inner box) => None\n" | ||
|
||
"class Class\n" | ||
" fun inner(): Inner val => Inner\n" | ||
" fun apply(): Wrap iso =>\n" | ||
" recover Wrap(inner()) end"; | ||
|
||
TEST_ERRORS_1(src, "receiver type is not a subtype of target type"); | ||
} |
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