Skip to content

Conversation

@nsajko
Copy link
Member

@nsajko nsajko commented Sep 12, 2024

Fixes #55756

@nsajko nsajko added error handling Handling of exceptions by Julia or the user error messages Better, more actionable error messages rationals The Rational type and values thereof labels Sep 12, 2024
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to make the same fix here?

nameof(T) === ex.func || print(io, T, ", ")


Bool(x::Rational) = x==0 ? false : x==1 ? true :
throw(InexactError(:Bool, Bool, x)) # to resolve ambiguity
throw(InexactError(:convert, Bool, x)) # to resolve ambiguity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can stay as :Bool?

throw(InexactError(:convert, Bool, x)) # to resolve ambiguity
(::Type{T})(x::Rational) where {T<:Integer} = (isinteger(x) ? convert(T, x.num)::T :
throw(InexactError(nameof(T), T, x)))
throw(InexactError(:convert, T, x)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could put a sentinel value here like Symbol(""), in which case the printer for InexactError knows to show the type as the called object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error handling Handling of exceptions by Julia or the user error messages Better, more actionable error messages rationals The Rational type and values thereof

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MethodError thrown while preparing to throw InexactError in conversion of Rational to Integer or Complex to Real

3 participants