Type solver doesn't understand booleans?

I have this block of code.
character is a new object I created using a module. Moving is a boolean variable and :Move is simply a method.

if character.Moving then
	return
end
	
character:Move()

This code should work fine, but the problem is that the type solver gets weird and warns that Type 'false' could not be converted into 'true' in an invariant context. This prevents :Move from being shown in autocomplete and highlights character with an orange underline…

Note that the :Move method is actually typed as function metatable.Move(self: type) in the module. I made it like that so the type solver will be able to access the properties of self.

Is this a bug?
Thanks for reading :slight_smile:

What’s funny to me is that Roblox’s built-in CameraWrapper module has the same issue…

function CameraWrapper:Enable()
    if self._enabled then
        return
    end

	self._enabled = true -- Type 'true' could not be converted into '(false?) & a'; this is because the 1st component of the intersection is `false?`, and `true` is not a subtype of `false?`

    self._cameraChangedConnection = game.Workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function()
        self:_connectCallbacks()        
    end)

    self:_connectCallbacks()  
end

Then in that case it is just a bug and I would recommend making a post in Engine Bugs

1 Like

Did just that!
Type solver doesn’t understand booleans in metatables? - Bug Reports / Studio Bugs - Developer Forum | Roblox
I’ll leave this post open for now in any case…

1 Like