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

Annotated function arguments and nil values #228

Open
snoopcatt opened this issue May 20, 2021 · 1 comment
Open

Annotated function arguments and nil values #228

snoopcatt opened this issue May 20, 2021 · 1 comment

Comments

@snoopcatt
Copy link

Hello.
Let's summarize our discussion on that.

Currently we have strange behaviour of annotated function arguments.
With some argument types (number, integer, number[], integer[], table) you can't pass nil, you will get a type error.
But with other types -- string, closure, userdata -- you can pass nil without any errors.

Example:

function test(a: number)
	print(a)
end
test()

ravi: t.lua:0: TOFLT: number expected

Another example:

function test(a: closure)
	print(a)
end
test()

nil (no error thrown)

I think behaviour of annotated arguments should be unified.
Most obvious solution is to make all arguments with specified type -- mandatory. (it is already that in JIT mode: #225)

In case when argument must be optional -- we have any type (or just omit annotation) as for now.

@dibyendumajumdar
Copy link
Owner

I have pushed some changes to make it consistent between the JIT and the interpreter. For now, this continues the existing model in the VM that NIL is valid value for Lua types - the Ravi add-on types do not allow NIL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants