Skip to content

wrong method called in @testset #21769

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

Open
martinholters opened this issue May 10, 2017 · 0 comments
Open

wrong method called in @testset #21769

martinholters opened this issue May 10, 2017 · 0 comments
Labels
testsystem The unit testing framework and Test stdlib

Comments

@martinholters
Copy link
Member

I think I found a small typo in the test of #21666, but it's curious that it hasn't lead to problems:

julia> using Base.Test

julia> struct F21666{T <: Base.TypeArithmetic}
           x::Float32
       end

julia> @testset "Reduced exactness of cumsum # 21666" begin
           Base.TypeArithmetic(::Type{F21666{T}}) where {T} = T # this should be T() I think
           Base.:+(x::F, y::F) where {F <: F21666} = F(x.x + y.x)
           Base.convert(::Type{Float64}, x::F21666) = Float64(x.x)
           v = zeros(300)
           cumsum(F21666{Base.ArithmeticRounds}.(v))
       end
Test Summary:                       |
Reduced exactness of cumsum # 21666 | No tests
Base.Test.DefaultTestSet("Reduced exactness of cumsum # 21666", Any[], 0, false)

julia> @testset "Reduced exactness of cumsum # 21666" begin # try again
           Base.TypeArithmetic(::Type{F21666{T}}) where {T} = T
           Base.:+(x::F, y::F) where {F <: F21666} = F(x.x + y.x)
           Base.convert(::Type{Float64}, x::F21666) = Float64(x.x)
           v = zeros(300)
           cumsum(F21666{Base.ArithmeticRounds}.(v))
       end
Reduced exactness of cumsum # 21666: Error During Test
  Got an exception of type MethodError outside of a @test
  MethodError: no method matching _cumsum!(::Array{F21666{Base.ArithmeticRounds},1}, ::Array{F21666{Base.ArithmeticRounds},1}, ::Int64, ::Type{Base.ArithmeticRounds})
  Closest candidates are:
    _cumsum!(::Any, ::Any, ::Any, ::Base.ArithmeticRounds) at multidimensional.jl:582
    _cumsum!(::Any, ::Any, ::Any, ::Base.ArithmeticUnknown) at multidimensional.jl:585
    _cumsum!(::Any, ::Any, ::Any, ::Base.TypeArithmetic) at multidimensional.jl:588
  Stacktrace:
   [1] macro expansion at ./REPL[10]:6 [inlined]
   [2] macro expansion at ./test.jl:856 [inlined]
   [3] anonymous at ./<missing>:?
   [4] eval(::Module, ::Any) at ./boot.jl:235
   [5] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
   [6] macro expansion at ./REPL.jl:97 [inlined]
   [7] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
Test Summary:                       | Error  Total
Reduced exactness of cumsum # 21666 |     1      1
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

The first time the @testset runs, the new method for Base.TypeArithmetic is ignored and the Base.ArithmeticUnknown() fallback is used. The second time the @testset runs, the new, faulty method for Base.TypeArithmetic is used leading to an error. It looks like the whole @testset runs in the same world - but that is not generally the case, is it?

BTW, I'd open a PR fixing the test, but I'm not sure whether the method definitions should be moved outside the @testset. They have global effect anyway, so it wouldn't hurt, but OTOH it's nice to have them in there just for grouping's sake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

No branches or pull requests

2 participants