-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow users to provide custom diagnostic messages when unwrapping calls #13597
Conversation
(&**value).into(), | ||
"call-non-callable", | ||
format_args!( | ||
"Method `__getitem__` is not callable on object of type '{}'.", |
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.
It's possible that we'll want to incorporate more information here from err
. The nice thing is we can if we want.
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.
In fact I would like to :) I think the diagnostic should include the type of __getitem__
that we found to not be callable. This could really help someone in debugging why their __getitem__
isn't callable. I think that type is already available in err
. I would suggest the phrasing "Method __getitem__
of type {} is not callable on object of type {}."
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 guess this will require some decisions about how to handle the UnionElement
and UnionElements
cases; I think we could just use the full union type and omit the detail of which element(s) were not callable, in this case? Don't have strong feelings though, open to options.
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.
Sounds good, I'll play around with it. I want something flexible but not too verbose or onerous.
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.
Alright, I went with printing the full union type for 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.
Lovely, thank you!
(&**value).into(), | ||
"call-non-callable", | ||
format_args!( | ||
"Method `__getitem__` is not callable on object of type '{}'.", |
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.
In fact I would like to :) I think the diagnostic should include the type of __getitem__
that we found to not be callable. This could really help someone in debugging why their __getitem__
isn't callable. I think that type is already available in err
. I would suggest the phrasing "Method __getitem__
of type {} is not callable on object of type {}."
(&**value).into(), | ||
"call-non-callable", | ||
format_args!( | ||
"Method `__class_getitem__` is not callable on object of type '{}'.", |
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.
Same comment as above, let's include the type we inferred for __class_getitem__
.
04ca994
to
18c7596
Compare
Summary
You can now call
return_ty_result
to operate on aResult
directly thereby using your own diagnostics, as in: