Skip to content
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

invalid error message for type parameter #34824

Closed
tpapp opened this issue Feb 20, 2020 · 2 comments · Fixed by #35862
Closed

invalid error message for type parameter #34824

tpapp opened this issue Feb 20, 2020 · 2 comments · Fixed by #35862
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error messages Better, more actionable error messages

Comments

@tpapp
Copy link
Contributor

tpapp commented Feb 20, 2020

julia> VERSION
v"1.5.0-DEV.299"

julia> struct Foo{T<:Real,TX<:AbstractVector{T},TFX}
       Δ::T
       x::TX
       fx::TFX
       residual_norm::T
       converged::Bool
       iterations::Int
       end

julia> function Foo::T1, x::AbstractVector{T2}, fx, residual_norm::T3, converged,
       iterations) where {T1 <: Real, T2 <: Real, T3 <: Real}
       T = promote_type(T1, T2, T3)
       Tx = T.(x)
       Foo{T,typeof(Tx)}(T(Δ), Tx, fx, T(residual_norm), converged, iterations)
       end
Foo

julia> Foo(1, [1.0, 2.0], nothing, 1.0, true, 0)
ERROR: MethodError: no method matching Foo{Float64,Array{Float64,1},TFX} where TFX(::Float64, ::Array{Float64,1}, ::Nothing, ::Float64, ::Bool, ::Int64)
Stacktrace:
 [1] Foo(::Int64, ::Array{Float64,1}, ::Nothing, ::Float64, ::Bool, ::Int64) at ./REPL[3]:5
 [2] top-level scope at REPL[4]:1

Note the where TFX(::Float64, ::Array{Float64,1}, ::Nothing, ::Float64, ::Bool, ::Int64).

(discussion on Discourse)

@JeffBezanson JeffBezanson added domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error messages Better, more actionable error messages labels Feb 29, 2020
@sostock
Copy link
Contributor

sostock commented Mar 30, 2020

I see two ways of repairing this, which do you prefer?

  1. Just adding parentheses:
    (Foo{Float64,Array{Float64,1},TFX} where TFX)(::Float64, ::Array{Float64,1}, ::Nothing, ::Float64, ::Bool, ::Int64)`
  2. Wrapping the type in (::Type{...}):
    (::Type{Foo{Float64,Array{Float64,1},TFX} where TFX})(::Float64, ::Array{Float64,1}, ::Nothing, ::Float64, ::Bool, ::Int64)`

For consistency, I would prefer the first option, since constructor methods of non-UnionAll types are not printed using (::Type{...}). It is also more concise. However, the second option is already used (e.g. when printing method tables), so it might be more familiar.

@tpapp
Copy link
Contributor Author

tpapp commented Mar 30, 2020

I would prefer just adding parentheses (it is more concise).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error messages Better, more actionable error messages
Projects
None yet
3 participants