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

missing narrowing type when not simple expression #760

Closed
fperrad opened this issue Jul 7, 2024 · 1 comment
Closed

missing narrowing type when not simple expression #760

fperrad opened this issue Jul 7, 2024 · 1 comment
Labels
semantics Unexpected or unsound behaviors

Comments

@fperrad
Copy link
Contributor

fperrad commented Jul 7, 2024

local function bar(v: any): any
   if not v is {string:any} or not v.field then
      return
   end
   return v.field  -- Error: cannot index key 'field' in any 'v' of type <any type>
end

local function baz(v: any): any
   if not v is {string:any} then
      return
   end
   if not v.field then
      return
   end
   return v.field  -- OK: v is {string:any}
end

The code of these 2 functions is equivalent.
But with a complex expression (ie. with a or), there is no narrowing type.

@hishamhm hishamhm added the semantics Unexpected or unsound behaviors label Jul 22, 2024
@hishamhm
Copy link
Member

I have revisited this, and this now works as expected since 0.24.1 (or, more precisely, since e457d38 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semantics Unexpected or unsound behaviors
Projects
None yet
Development

No branches or pull requests

2 participants