8000 assert() only excludes nil type after expression evaluated · Issue #336 · luau-lang/luau · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

assert() only excludes nil type after expression evaluated #336

New issue

Have a question about this project? Sign up for 8000 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

Closed
kirdaaa opened this issue Feb 2, 2022 · 0 comments · Fixed by #340
Closed

assert() only excludes nil type after expression evaluated #336

kirdaaa opened this issue Feb 2, 2022 · 0 comments · Fixed by #340
Assignees
Labels
bug Something isn't working

Comments

@kirdaaa
Copy link
kirdaaa commented Feb 2, 2022

The following cases emit warning:

local function foo(x: number?): number
  return assert(x)
end

TypeError: Type 'number?' could not be converted into 'number'

local foo: number? = nil
local bar: number = assert(foo)

TypeError: Type 'number?' could not be converted into 'number'

This is incorrect, it should convert number? to number.

But if the code is separated on multiple lines, everything works correctly:

local function foo(x: number?): number
  assert(x)
  return x
end
local foo: number? = nil
assert(foo)
local bar: number = foo
@zeux zeux added the bug Something isn't working label Feb 2, 2022
@zeux zeux closed this as completed in #340 Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants
0