Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-recover constructor expressions when assigning to an explicit type. #702

Closed
jemc opened this issue Apr 6, 2016 · 0 comments · Fixed by #4124
Closed

Auto-recover constructor expressions when assigning to an explicit type. #702

jemc opened this issue Apr 6, 2016 · 0 comments · Fixed by #4124
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jemc
Copy link
Member

jemc commented Apr 6, 2016

In cases where we are constructing a new object and assigning to that to an explicit type (either as an actual assignment with an explicit type or as an argument passed to a method), and there is a subtyping issue in that assignment which would be solved by surrounding the constructor in a recover ... end, we want to auto-recover the expression and allow that recover ... end to be implicit rather than explicit.

Some examples:

let a: Array[String val] val = ["foo", "bar"]
class Foo
  new create(v: U8) =>
    // ...

primitive Bar
  fun take_foo(foo: Foo iso) =>
    // ...

// ...
Bar.take_foo(Foo(88))

This would also solve #415.

@jemc jemc self-assigned this Apr 10, 2016
@SeanTAllen SeanTAllen added help wanted Extra attention is needed enhancement New feature or request and removed complexity: requires context labels May 12, 2020
SeanTAllen pushed a commit that referenced this issue Sep 2, 2021
…ilePath (#3819)

Implementation of RFC #702.

https://github.com/ponylang/rfcs/blob/main/text/0070-filepath-constructor.md

Splits FilePath's create into two different constructors where the new constructor `from` is partial like the current `create` and in the process, makes `create` non-partial. It does this by making `create`
chalcolith added a commit that referenced this issue Jul 5, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants