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

intersecting class type by shape type results in `never` and causes loss of type inference - new solver bug #1261

Open deviaze opened 1 month ago

deviaze commented 1 month ago

As shown in the following screenshot, the new solver correctly resolves the type of HumanoidStateTypes in HumanoidStateTypes.Freefall (line 24) but resolves the type of HumanoidStateTypes to never on subsequent attempts to use the variable (lines 26 & 28).

image

According to Drakontas on the Roblox OSS Discord server (alexmccord), this is because:

it's intersecting Enum.HumanoidStateType.Freefall which is of type Enum.HumanoidStateType by a table (that should be viewed as a shape type) with Freefall property and intersecting a class type by a shape type shouldn't result in never, so i think this is a bug in simplification

Here's a minimal repro with a different Enum:

-- assume roblox dev environment with FFlag DebugLuauDeferredConstraintResolution = true 
local UserInputTypes = Enum.UserInputType -- hover shows: local UserInputTypes: Enum.UserInputType

local function handleInputType(someInputType: Enum.UserInputType)
      if someInputType == UserInputTypes.Focus then -- hover shows: local UserInputTypes: Enum.UserInputType
            print("client tabbed in")
      elseif someInputType == UserInputTypes then -- hover shows: local UserInputTypes: never

      end
end

(edits: fixed screenshot (Enum.HumanoidStateType.Walking doesnt exist), line number)