Nullable types and inference

Dan Smith daniel.smith at oracle.com
Tue Apr 30 21:22:14 UTC 2019


> On Apr 26, 2019, at 7:44 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> There is already a _null type_, and we’ve defined it so that for every reference type R, Null <: R (JLS 4.10.). In order to make inference work for nullable values, we need to state that for a zero-default value type V:
> 
>    Null <! V
>    Null <: V?
> 
> and that LUB(V, Null) = V?
> 
> When we gather constraints in 18.1, in addition to adding the upper bound on alpha, we also add in lower bounds Null <: alpha_i for erased type vars.  
> 
> We adjust 18.4 to not consider Null to be a proper lower bound for purposes of resolution.


I agree with the spirit of this, but I've actually been meaning for awhile to push on getting rid of the null type, which is barely a type (like needing special treatment in 18.4). The goal would be to treat 'null' as a poly expression instead.

That aside, yes, we'll need a way to identify which inference vars are constrained to be nullable (and maybe which are constrained to be non-nullable?). If it's not with a type, we can do it with a special-purpose bound and corresponding resolution rules.



More information about the valhalla-spec-observers mailing list