Skip to content
This repository

Constructor returns nothing #2161

Closed
adambrewster opened this Issue · 1 comment

3 participants

adambrewster Keno Fischer Jeff Bezanson
adambrewster

The following test fails on the second to last line. Maybe I'm an idiot, but this behavior seems really weird if it's not a bug. Running bda9432 on a 32-bit machine in case that matters. The commented out version of the constructor ABCD seems to make things work.

type AB{T<:Real}
    a::T
    b::T
end
AB{T<:Real}(a::T, b::T) = AB{T}(a, b)
AB(a::Real, b::Real) = AB(promote(a, b)...)
@test typeof(AB(0.0, 0)) != Nothing
@test typeof(AB(0, 0.0)) != Nothing

type ABC{T<:Real}
    a::T
    b::T
    c::T
end
ABC{T<:Real}(a::T, b::T, c::T) = ABC{T}(a, b, c)
ABC(a::Real, b::Real, c::Real) = ABC(promote(a, b, c)...)
@test typeof(ABC(0.0, 0, 0)) != Nothing
@test typeof(ABC(0, 0.0, 0)) != Nothing
@test typeof(ABC(0, 0, 0.0)) != Nothing

type ABCD{T<:Real}
    a::T
    b::T
    c::T
    d::T
end
ABCD{T<:Real}(a::T, b::T, c::T, d::T) = ABCD{T}(a, b, c, d)
ABCD(a::Real, b::Real, c::Real, d::Real) = ABCD(promote(a, b, c, d)...)
#ABCD(a::Real, b::Real, c::Real, d::Real) = ABCD(promote(a, promote(b, promote(c, d)...)...)...)

@test typeof(ABCD(0.0, 0, 0, 0)) != Nothing
@test typeof(ABCD(0, 0.0, 0, 0)) != Nothing
@test typeof(ABCD(0, 0, 0.0, 0)) != Nothing # fails here
@test typeof(ABCD(0, 0, 0, 0.0)) != Nothing

[pao: formatting, note that @test (or any Julia macro call) outside a quote block in an issue will ping that user on GitHub, who must be very cross with us by now]

Keno Fischer
Collaborator

Seems like a bug to me as well.

/cc @JeffBezanson

bsxfan bsxfan referenced this issue in JuliaDiff/ForwardDiff.jl
Closed

Matrix-valued DualNumber: coding problems #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.