-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Suggest wrapping value in Ok
or Error
if it makes sense
#3663
base: main
Are you sure you want to change the base?
Suggest wrapping value in Ok
or Error
if it makes sense
#3663
Conversation
Looks like you forgot to accept the snapshot again :) |
Ah yeah this time it's intentional, I'm not really satisfied with how the error looks for case expressions 😆 |
4069083
to
9560d6c
Compare
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.
Nice! Left 1 comment inline.
Could we have some tests for in use
and returned from a function annotated as being result? Those will be the most common I think.
Hey! 💜 I tried your
The last one means that your new hint doesn't work for these cases for example: pub fn wibble() -> Result(List(String), Nil) {
[] // List(a) `same_as` List(String)
}
pub fn wobble() -> Result(List(b), Nil) {
[] // List(a) `same_as` List(b)
} I feel like it would be more useful if unbound type variables where allowed to match any type on the right-hand side; Something like ~ yoshi |
Hello! Are you still working on this one? Thanks |
Oh my I hadn't noticed the conflicts, once those are solved I think this is ready for review! |
bcc7a89
to
134eb59
Compare
This is ready now! |
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.
Wonderful, thank you! Left a few small notes
compiler-core/src/type_.rs
Outdated
(Type::Tuple { .. }, Type::Fn { .. } | Type::Named { .. }) => false, | ||
(one @ Type::Tuple { .. }, Type::Var { type_ }) => { | ||
type_.as_ref().borrow().same_as_other_type(one) | ||
} |
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.
Could you merge all the ones with var on the right hand side and move the new merged clause along with clause with var on the left up to the top please.
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.
Changed it! Not sure if it's the look you wanted, let me know if it's better now
( | ||
TypeVar::Unbound { .. }, | ||
Type::Named { .. } | Type::Fn { .. } | Type::Tuple { .. }, | ||
) => false, |
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.
How come this is false?
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 thought an unbound variable is never meant to survive the type inference process, so I chose a safe default there
4873d2b
to
3ecd9c9
Compare
3ecd9c9
to
d280253
Compare
This should be ready now! |
As suggested by @GearsDatapacks the compiler can now suggest to wrap a value into an
Ok
/Error
if it would make the types line up:This is a WIP because I still have to figure out how to pretty print this information in pattern matching branches, right now it looks quite bad 😁