luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau-lang.org
MIT License
3.79k stars 349 forks source link

Cannot cast into union with literal with new solver's strict mode #1302

Open Ketasaja opened 1 week ago

Ketasaja commented 1 week ago

Tested on 0.631, with no warnings in non-strict mode.

--!strict
local _v = false :: string | false -- TypeError: Cannot cast 'boolean' into 'false | string' because the types are unrelated
local _w = false :: string | boolean
local _x: string | false = false
local _y = "" :: number | "" -- TypeError: Cannot cast 'string' into '"" | number' because the types are unrelated
local _z = "" :: number | string