Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New type solver throws type error with unclear message when return type is optional #1400

Open
Daw588 opened this issue Sep 12, 2024 · 1 comment
Labels
bug Something isn't working new solver This issue is specific to the new solver.

Comments

@Daw588
Copy link

Daw588 commented Sep 12, 2024

The new type solver throws type error with unclear message when return type is optional and the return keyword is used without a value.

function RandBool(): boolean?
	if math.random() > 0.5 then
		return true
	end
	return -- TypeError: Type pack '' could not be converted into 'boolean?' Luau(1035)
end

However, this does not occur when the return keyword is used with nil.

function RandBool(): boolean?
	if math.random() > 0.5 then
		return true
	end
	return nil -- OK
end
@Daw588 Daw588 added the bug Something isn't working label Sep 12, 2024
@aatxe aatxe added the new solver This issue is specific to the new solver. label Sep 12, 2024
@aatxe
Copy link
Collaborator

aatxe commented Sep 12, 2024

Thanks for the report, agreed the error message could definitely be better here, but an empty typepack is indeed not at the type boolean? (you can observe the difference by select('#', ...) on the result of your two versions of RandBool).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new solver This issue is specific to the new solver.
Development

No branches or pull requests

2 participants