diff --git a/base/nullable.jl b/base/nullable.jl index 11f472f627080..21da641206200 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -22,11 +22,11 @@ convert{T}(::Type{Nullable{T}}, ::Void) = Nullable{T}() convert( ::Type{Nullable }, ::Void) = Nullable{Union{}}() function show{T}(io::IO, x::Nullable{T}) - if x.isnull - print(io, "Nullable{"); show(io, T); print(io, "}()") - else - print(io, "Nullable("); show(io, x.value); print(io, ")") + print(io, "Nullable{", T, "}(") + if !isnull(x) + show(io, x.value) end + print(io, ')') end get(x::Nullable) = x.isnull ? throw(NullException()) : x.value diff --git a/test/nullable.jl b/test/nullable.jl index 958dc8a50825b..b7c00a8c3c48e 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -94,37 +94,37 @@ p1s = [ ] p2s = [ - "Nullable(false)", - "Nullable('\0')", - "Nullable(Float16(0.0))", - "Nullable(0.0f0)", - "Nullable(0.0)", - "Nullable(0)", - "Nullable(0)", - "Nullable(0)", - "Nullable(0)", - "Nullable(0)", - "Nullable(0x0000)", - "Nullable(0x00000000)", - "Nullable(0x0000000000000000)", - "Nullable(0x00)", + "Nullable{Bool}(false)", + "Nullable{Char}('\0')", + "Nullable{Float16}(Float16(0.0))", + "Nullable{Float32}(0.0f0)", + "Nullable{Float64}(0.0)", + "Nullable{Int128}(0)", + "Nullable{Int16}(0)", + "Nullable{Int32}(0)", + "Nullable{Int64}(0)", + "Nullable{Int8}(0)", + "Nullable{UInt16}(0x0000)", + "Nullable{UInt32}(0x00000000)", + "Nullable{UInt64}(0x0000000000000000)", + "Nullable{UInt8}(0x00)", ] p3s = [ - "Nullable(true)", - "Nullable('\x01')", - "Nullable(Float16(1.0))", - "Nullable(1.0f0)", - "Nullable(1.0)", - "Nullable(1)", - "Nullable(1)", - "Nullable(1)", - "Nullable(1)", - "Nullable(1)", - "Nullable(0x0001)", - "Nullable(0x00000001)", - "Nullable(0x0000000000000001)", - "Nullable(0x01)", + "Nullable{Bool}(true)", + "Nullable{Char}('\x01')", + "Nullable{Float16}(Float16(1.0))", + "Nullable{Float32}(1.0f0)", + "Nullable{Float64}(1.0)", + "Nullable{Int128}(1)", + "Nullable{Int16}(1)", + "Nullable{Int32}(1)", + "Nullable{Int64}(1)", + "Nullable{Int8}(1)", + "Nullable{UInt16}(0x0001)", + "Nullable{UInt32}(0x00000001)", + "Nullable{UInt64}(0x0000000000000001)", + "Nullable{UInt8}(0x01)", ] # show{T}(io::IO, x::Nullable{T})