From c5113e74cd96bf0fb528a301b9e45534c3a63494 Mon Sep 17 00:00:00 2001 From: Jason Carr Date: Mon, 4 Jul 2022 14:00:20 -0400 Subject: [PATCH] Add tests; support val better --- src/libponyc/type/cap.c | 3 + test/libponyc-run/ctor-autorecover/main.pony | 5 + test/libponyc/recover.cc | 109 +++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/src/libponyc/type/cap.c b/src/libponyc/type/cap.c index a5aeaa850b..f3ff12a87b 100644 --- a/src/libponyc/type/cap.c +++ b/src/libponyc/type/cap.c @@ -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: diff --git a/test/libponyc-run/ctor-autorecover/main.pony b/test/libponyc-run/ctor-autorecover/main.pony index 54d34d3804..3d2064455f 100644 --- a/test/libponyc-run/ctor-autorecover/main.pony +++ b/test/libponyc-run/ctor-autorecover/main.pony @@ -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 @@ -31,3 +33,6 @@ class Foo primitive Bar fun take_foo(foo: Foo iso) => None + + fun take_foo_val(foo: Foo val) => + None diff --git a/test/libponyc/recover.cc b/test/libponyc/recover.cc index 71c32cb390..7e6ea1727b 100644 --- a/test/libponyc/recover.cc +++ b/test/libponyc/recover.cc @@ -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 =