-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-recover constructor expressions (#4124)
This PR adds checks when assigning a constructor expression or passing one as a parameter to see if it can be auto-recovered, and if so, does not output a subtyping error. E.g. for the following code: ``` actor Main new create(env: Env) => Bar.take_foo(Foo(88)) let bar: Foo iso = Foo(88) class Foo new create(v: U8) => None primitive Bar fun take_foo(foo: Foo iso) => None ``` We'd previously get errors on both lines in Main.create(); whereas with this PR they are now accepted. Fixes #702 Co-authored-by: Sean T Allen <sean@seantallen.com> Co-authored-by: Jason Carr <jcarr250@protonmail.com>
- Loading branch information
1 parent
ab6a6a3
commit 7b01704
Showing
7 changed files
with
300 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Allow constructor expressions to be auto-recovered in assignments or arguments | ||
|
||
Previously for the following code: | ||
|
||
```pony | ||
actor Main | ||
new create(env: Env) => | ||
Bar.take_foo(Foo(88)) | ||
let bar: Foo iso = Foo(88) | ||
class Foo | ||
new create(v: U8) => | ||
None | ||
primitive Bar | ||
fun take_foo(foo: Foo iso) => | ||
None | ||
``` | ||
|
||
You'd get compilation errors "argument not assignable to parameter" and "right side must be a subtype of left side" for the two lines in `Main.create()`. | ||
|
||
We've added checks to see if the constructor expressions can be implicitly auto-recovered, and if they can, no compilation error is generated. | ||
|
||
This only applies to cases where the type of the parameter (or the `let` binding) is a simple type, i.e. not a union, intersection or tuple 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
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,38 @@ | ||
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 | ||
// see RecoverTest.CantAutoRecover_CtorArgWithNonSendableArg | ||
// and RecoverTest.CantAutoRecover_CtorAssignmentWithNonSendableArg | ||
|
||
//let s: String ref = String | ||
//Bar.take_foo(Foo.from_str(s)) -> argument not assignable to parameter | ||
//let baz: Foo iso = Foo.from_str(s) -> right side must be a subtype of left side | ||
|
||
// verify that inheritance hasn't broken | ||
let x = String | ||
let y: String ref = x | ||
|
||
class Foo | ||
new create() => | ||
None | ||
new ref from_u8(v: U8) => | ||
None | ||
new ref from_str(s: String ref) => | ||
None | ||
|
||
primitive Bar | ||
fun take_foo(foo: Foo iso) => | ||
None | ||
|
||
fun take_foo_val(foo: Foo val) => | ||
None |
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