Im not sure if this is a BUG but --!strict doen't behave normaly

I want to know if this is a BUG or not.

I wrote this code:

--!strict
local normalizedChild: Folder = nil

And I got no warning from the Strict type checker. I assigned a Folder type variable to nil. No warnings. No blue line under the code.

Here is the whole function definition:

--!strict
Shared.GetFoldersLinkSingleton = function(parent: Folder | Workspace, ...: string): Folder?
	if typeof(parent) ~= "Instance" then
		return nil
	end
	if not parent:IsA("Folder") and not parent:IsA("Workspace") then
		return nil
	end
	
	local arguments = {...}
	if #arguments <= 0 then
		return nil
	end
	
	for _, argument in ipairs(arguments) do
		if typeof(argument) ~= "string" then
			return nil
		end
	end
	
	local currentParent = parent
	for _, argument in ipairs(arguments) do
		local children = currentParent:GetChildren()
		
		local normalizedChild: Folder = nil
		for _, child in ipairs(children) do
			if child.Name ~= argument then
				continue
			end
			if not child:IsA("Folder") then
				continue
			end
			normalizedChild = child
			break
		end
		
		if not normalizedChild then
			local newNormalizedChild = Instance.new("Folder")
			newNormalizedChild.Name = argument
			newNormalizedChild.Parent = currentParent
			normalizedChild = newNormalizedChild
		end
		currentParent = normalizedChild
	end
	
	return currentParent :: Folder
end

The line correctly has a warning with the “New Luau type solver” beta feature enabled.

This is not a bug. Luau strict allows nil assignments to typed variables.

local normalizedChild: Folder? = nil
local normalizedChild = nil

Both are valid, and neither will produce a strict-mode error.

I don’t see why people put themselves through the hassle of strict unless you’re actually using something to slam into something as the type of variable only and you’re not checking for that. Like you’re actually relying on type enforcement. Most of the time there is no need for this.

Strict mode isn’t providing any real benefit here. You’re not actively using it to enforce or check types. It’s not “better than”.. at its core, it’s just a mode for enforcing types.

The type checker should give a warning in my opinion, because I assigned nil to a variable that didn’t used ? after the type annotation.

There is a diffrence between:

local var: BasePart = nil

and

local var: BasePart? = nil

The question mark should allow nil values to get assingned, and the absence of the ? should not. You used ?, so Luau type checker should not give a warning there, but I didn’t used ? in my example and I still didn’t got a warning

He said it does give a warning with the type solver beta feature enabled, check if it’s turned off in your beta settings

Oh. My bad, Thank you. The Beta Feature made it work.

1 Like

I enabled the beta feature, it worked for this case, but made other wierd errors in the code base that have no sense. I will disable it and ignore all the wierd errors or absence of errors until the type checker becomes better.