-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
Proper try
keyword
#7296
Proper try
keyword
#7296
Conversation
409e614
to
0e317c8
Compare
@@ -33,7 +33,7 @@ impl Problems { | |||
const YELLOW: &str = ANSI_STYLE_CODES.yellow; | |||
const RESET: &str = ANSI_STYLE_CODES.reset; | |||
|
|||
println!( | |||
print!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to be printing
3 errors and 0 warnings found in <ignored for test> ms
.
now we get
3 errors and 0 warnings found in <ignored for test> ms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried keeping println!
and putting the period at the end of this statement, but there are multiple places where we append text after this line that would break if we always put the period here. For another PR 🤷🏼
@@ -10449,6 +10453,7 @@ All branches in an `if` must have the same type! | |||
|
|||
This 2nd argument to `map` has an unexpected type: | |||
|
|||
4│ A := U8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised to see this opaque definition included, but it's here because we now include the full def body in these diagnostics. This test's body actually gets turned into:
main =
A := U8
List.map [1u16, 2u16, 3u16] @A
So the inclusion of the opaque type makes sense, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 😄
@@ -14701,6 +14706,54 @@ All branches in an `if` must have the same type! | |||
"### | |||
); | |||
|
|||
test_report!( | |||
return_in_bare_statement, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are duplicated versions of try
-based tests, meaning we now have separate tests for try
and return
|
||
This 1st argument to this function has an unexpected type: | ||
|
||
9│> readFile filePath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validates that we see the full pipe instead of just the readFile filePath
arg, which was confusing.
0e317c8
to
eedade8
Compare
@@ -1237,8 +1268,8 @@ fn to_expr_report<'b>( | |||
&category, | |||
found, | |||
expected_type, | |||
region, | |||
Some(expr_region), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were previously swapped, meaning we wouldn't show an expression and some context, but just the expression. Errors should be more useful (a.k.a. have more context) now.
try
keywordtry
keyword
@ayazhafiz I copied the On the first set of comments: for me to handle improving error reporting on problematic style of statement, e.g. foo = \{} ->
if True then
return 1
else
2
3 You suggested the following, which I'm not understanding:
A couple of questions:
|
@smores56 sorry the opaque initial comment. What I am suggesting is distinguishing between With the example above, I would suggest adding these constraints
After solving, the types will be
Now we can see that we should emit a warning because the standalone if/else produces a value (of type I suppose that for your case you actually want to unify the standalone expression to the empty record to see whether the warning should be emitted, right? Maybe my note about the constraints was wrong. I'm not sure what constraint is most useful, I just mean to say taking a type-directed approach to determine whether the statement could evaluate to a value that needs to be bound is probably better than walking the AST (and also handles cases where the statement calls a function that never returns, for example the infinite loop) If we take a couple other cases this works just as well
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice improvement for try
, I particularly enjoyed seeing the new error reporting. 😄
Thanks @lukewilliamboswell ! Another PR, coming at you in a few minutes. |
Man... you're too efficient |
A working version of
try
implemented as a keyword instead of a desugaring. This allows users to get better type errors when they usetry
incorrectly.Though we plan to likely drop
try
once we move to static dispatch, this implementation should be easy to migrate to a?
version without too much effort, meaning this is "future-proof".try
parsing, minor update to desugaringTryTargetConstraint
that validates that something is Result-shaped during thetry
target validation process