xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Nullable type unions don't work as expected #142

Closed thekid closed 2 years ago

thekid commented 2 years ago

The union types RFC specifies in its nullable union types section:

An earlier version of this RFC proposed to use ?(T1|T2) for nullable union types instead, to avoid having two ways of expressing nullability in PHP. [...] The discussion feedback was overwhelmingly in favor of supporting the T1|T2|null notation.

XP Compiler supports both notations. However, either raise errors when compiled to PHP8.0+

thekid commented 2 years ago

The official way of writing this (int|string|null) was fixed by xp-framework/ast@9cfc02d and released in https://github.com/xp-framework/ast/releases/tag/v8.2.0

thekid commented 2 years ago

However, int|string|null yields the following when used with XP core reflection:

// PHP 8.2
lang.Nullable<?string|int>

// PHP < 8.2
lang.TypeUnion<int|string|void>

...which is inconsistent - the first form is what we should be getting in both cases.

thekid commented 2 years ago

For PHP 7, this fix is needed: https://github.com/xp-framework/core/pull/316

thekid commented 2 years ago

For PHP 7, this fix is needed: xp-framework/core#316

✅ Released in bugfix release https://github.com/xp-framework/core/releases/tag/v11.4.2

thekid commented 2 years ago

Fix released in https://github.com/xp-framework/compiler/releases/tag/v8.5.1