-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect "field not initialized" error with try/else
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
- Loading branch information
1 parent
d330436
commit ab85ab2
Showing
5 changed files
with
77 additions
and
0 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,15 @@ | ||
## Fix incorrect "field not initialized" error with try/else | ||
|
||
Previously, due to a bug in the compiler's try/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 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,9 @@ | ||
actor Main | ||
var _s: (String | None) | ||
|
||
new create(env: Env) => | ||
try | ||
_s = "".usize()?.string() | ||
else | ||
_s = None | ||
end |
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,9 @@ | ||
actor Main | ||
var _s: (String | None) | ||
|
||
new create(env: Env) => | ||
try | ||
"".usize()?.string() | ||
then | ||
_s = "initialized" | ||
end |
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