Skip to content

Commit

Permalink
Add tests; support val better
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Carr committed Jul 4, 2022
1 parent 2c5535c commit c5113e7
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libponyc/type/cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,9 @@ bool cap_safetomove(token_id into, token_id cap, direction direction)
break;

case TK_TRN:
// when recovering to val, anything which has no
// writable aliases elsewhere is fine
case TK_VAL:
switch(cap)
{
case TK_ISO:
Expand Down
5 changes: 5 additions & 0 deletions test/libponyc-run/ctor-autorecover/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ actor Main
new create(env: Env) =>
// zero-parameter constructor as argument and assignment
Bar.take_foo(Foo)
Bar.take_foo_val(Foo)
let qux: Foo iso = Foo

// sendable-parameter constructor as argument and assignment
Bar.take_foo(Foo.from_u8(88))
Bar.take_foo_val(Foo.from_u8(88))
let bar: Foo iso = Foo.from_u8(88)

// non-sendable parameter ctor and assignment must fail
Expand All @@ -31,3 +33,6 @@ class Foo
primitive Bar
fun take_foo(foo: Foo iso) =>
None

fun take_foo_val(foo: Foo val) =>
None
109 changes: 109 additions & 0 deletions test/libponyc/recover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,115 @@ TEST_F(RecoverTest, CanWriteTrn_TrnAutoRecovery)

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetIso_CtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create() =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" let a_iso: A iso = A\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, VarIso_CtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create() =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" var a_iso: A iso = A\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetTrn_CtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create() =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" var a_trn: A trn = A\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetVal_RefCtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create() =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" var a_val: A val = A\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetVal_BoxCtorAutoRecovery)
{
const char* src =
"class A\n"
" new box create() =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" var a_val: A val = A\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetIso_ArgsCtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create(s: String box) =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" let s: String val = \"\"\n"
" let a_iso: A iso = A(s)\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetTrn_ArgsCtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create(s: String box) =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" let s: String val = \"\"\n"
" let a_trn: A trn = A(s)\n";

TEST_COMPILE(src);
}
TEST_F(RecoverTest, LetVal_ArgsCtorAutoRecovery)
{
const char* src =
"class A\n"
" new ref create(s: String box) =>\n"
" None\n"

"actor Main\n"
" new create(env: Env) =>\n"
" let s: String val = \"\"\n"
" let a_val: A val = A(s)\n";

TEST_COMPILE(src);
}


TEST_F(RecoverTest, CantAutoRecover_CtorArgWithNonSendableArg)
{
const char* src =
Expand Down

0 comments on commit c5113e7

Please sign in to comment.