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

Open
fperrad opened this issue Jul 7, 2024 · 0 comments
Open

missing narrowing type when not simple expression #760

fperrad opened this issue Jul 7, 2024 · 0 comments
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
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