{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/19748","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/19748/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/19748/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/19748/events","html_url":"https://github.com/JuliaLang/julia/issues/19748","id":197946561,"number":19748,"title":"promoting `Nullable` with anything?","user":{"login":"JeffBezanson","id":744556,"avatar_url":"https://avatars.githubusercontent.com/u/744556?v=3","gravatar_id":"","url":"https://api.github.com/users/JeffBezanson","html_url":"https://github.com/JeffBezanson","followers_url":"https://api.github.com/users/JeffBezanson/followers","following_url":"https://api.github.com/users/JeffBezanson/following{/other_user}","gists_url":"https://api.github.com/users/JeffBezanson/gists{/gist_id}","starred_url":"https://api.github.com/users/JeffBezanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeffBezanson/subscriptions","organizations_url":"https://api.github.com/users/JeffBezanson/orgs","repos_url":"https://api.github.com/users/JeffBezanson/repos","events_url":"https://api.github.com/users/JeffBezanson/events{/privacy}","received_events_url":"https://api.github.com/users/JeffBezanson/received_events","type":"User","site_admin":false},"labels":[{"id":210700,"url":"https://api.github.com/repos/JuliaLang/julia/labels/decision","name":"decision","color":"F08000","default":false},{"id":437820724,"url":"https://api.github.com/repos/JuliaLang/julia/labels/nullable","name":"nullable","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-29T03:03:32Z","updated_at":"2016-12-29T15:39:49Z","closed_at":null,"body":"e79e84654a40e8189e5dfbd55df232ae6c82a213 added the following definition:\r\n\r\n```\r\npromote_rule{S,T}(::Type{Nullable{S}}, ::Type{T}) = Nullable{promote_type(S, T)}\r\n```\r\n\r\nThis might have unintended consequences. For example, we have:\r\n\r\n```\r\njulia> promote(1, \"\")\r\n(1,\"\")\r\n\r\njulia> promote(Nullable(1), \"\")\r\n(Nullable{Any}(1),Nullable{Any}(\"\"))\r\n```\r\n\r\nGiven a `Nullable` and something completely unrelated, you get two `Nullable{Any}`s. I don't think two types should have a non-identity promotion just because one is Nullable. This was not obvious at the time.\r\n\r\nI propose this definition instead:\r\n\r\n```\r\nfunction promote_rule{S,T}(::Type{Nullable{S}}, ::Type{T})\r\n    R = promote_type(S, T)\r\n    if R <: S || R <: T\r\n    else\r\n        if S <: R || T <: R\r\n            return R\r\n        end\r\n    end\r\n    return Nullable{R}\r\nend\r\n```\r\n\r\nThis says to leave the values alone if the promoted type (R) is a strict supertype of T or S, and otherwise promote as before. For example\r\n\r\n```\r\njulia> promote(Nullable(1),2.4)\r\n(Nullable{Float64}(1.0),Nullable{Float64}(2.4))\r\n\r\njulia> promote(Nullable(1),\"\")\r\n(Nullable{Int64}(1),\"\")\r\n```\r\n\r\nThis definition can still be type-inferred (since we can now handle constant conditions well)."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/269647562","html_url":"https://github.com/JuliaLang/julia/issues/19748#issuecomment-269647562","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/19748","id":269647562,"user":{"login":"JeffBezanson","id":744556,"avatar_url":"https://avatars.githubusercontent.com/u/744556?v=3","gravatar_id":"","url":"https://api.github.com/users/JeffBezanson","html_url":"https://github.com/JeffBezanson","followers_url":"https://api.github.com/users/JeffBezanson/followers","following_url":"https://api.github.com/users/JeffBezanson/following{/other_user}","gists_url":"https://api.github.com/users/JeffBezanson/gists{/gist_id}","starred_url":"https://api.github.com/users/JeffBezanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeffBezanson/subscriptions","organizations_url":"https://api.github.com/users/JeffBezanson/orgs","repos_url":"https://api.github.com/users/JeffBezanson/repos","events_url":"https://api.github.com/users/JeffBezanson/events{/privacy}","received_events_url":"https://api.github.com/users/JeffBezanson/received_events","type":"User","site_admin":false},"created_at":"2016-12-29T15:39:49Z","updated_at":"2016-12-29T15:39:49Z","body":"There was a piece of code here: https://github.com/JuliaIO/JSON.jl/issues/39#issuecomment-194922317\r\nthat used `vcat` to combine values before assigning them to fields of another type. Since one was nullable, all values were converted to nullable and didn't match the expected field types."}}
{"actor":{"display_login":"JeffBezanson"}}