luau icon indicating copy to clipboard operation
luau copied to clipboard

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

Open deviaze opened this issue 1 year ago • 0 comments

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)

deviaze avatar May 23 '24 02:05 deviaze