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

Fix incorrect "field not initialized" error with try/else #4011

Merged
merged 1 commit into from
Feb 16, 2022

Conversation

SeanTAllen
Copy link
Member

Previously, due to a bug in the compiler's while/else handling code, the
following code would be rejected as not initializing all object fields:

actor Main
  var _s: (String | None)

  new create(env: Env) =>
    try
      _s = "".usize()?.string()
    else
      _s = None
    end

This commit fixes try/else handling in refer_try so that it matches the
general shape of refer_if, refer_while, and refer_repeat. It differs from
them because try isn't a scope and we want to push everything into the then
clause as it can fulfill initialization all on its own or if it doesn't handle
initialization, we can still get it from the try body and the else clause.

Closes #3283

@SeanTAllen SeanTAllen requested a review from a team February 15, 2022 04:32
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Feb 15, 2022
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 15, 2022
@ergl ergl self-assigned this Feb 15, 2022
@ergl
Copy link
Member

ergl commented Feb 15, 2022

Assigned myself to these ones just so I can double check how we do this for if-then-else, but if anyone else with more expertise with the compiler thinks these PRs lookg good, feel free to merge them.

@ergl
Copy link
Member

ergl commented Feb 16, 2022

@SeanTAllen This needs to be rebased after merging #4009

@SeanTAllen SeanTAllen force-pushed the issue-3283-try-no-scope branch from f32906f to 62ac4d4 Compare February 16, 2022 13:38
Previously, due to a bug in the compiler's while/else handling code, the
following code would be rejected as not initializing all object fields:

```pony
actor Main
  var _s: (String | None)

  new create(env: Env) =>
    try
      _s = "".usize()?.string()
    else
      _s = None
    end
```

This commit fixes try/else handling in `refer_try` so that it matches the
general shape of `refer_if`, `refer_while`, and `refer_repeat`. It differs from
them because `try` isn't a scope and we want to push everything into the `then`
clause as it can fulfill initialization all on its own or if it doesn't handle
initialization, we can still get it from the try body and the else clause.

Closes #3283
@SeanTAllen SeanTAllen force-pushed the issue-3283-try-no-scope branch from 62ac4d4 to a818f54 Compare February 16, 2022 15:31
@SeanTAllen SeanTAllen merged commit f82f3f7 into main Feb 16, 2022
@SeanTAllen SeanTAllen deleted the issue-3283-try-no-scope branch February 16, 2022 16:54
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 16, 2022
github-actions bot pushed a commit that referenced this pull request Feb 16, 2022
github-actions bot pushed a commit that referenced this pull request Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler doesn't see required assignment in try..else structure.
3 participants