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

edge case of checking of the number of return value #741

Open
fperrad opened this issue Mar 24, 2024 · 2 comments
Open

edge case of checking of the number of return value #741

fperrad opened this issue Mar 24, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@fperrad
Copy link
Contributor

fperrad commented Mar 24, 2024

local function bar()
end

local function foo()
   if true then
      return bar()  -- ERROR: in return value: excess return values, expected 0 (), got 1 (())
   else
      bar()
      return  -- OK but not idiomatic
   end
end

Note: with nil as explicit return, the checker is happy

local function bar(): nil
end

local function foo(): nil
   return bar()
end
@hishamhm hishamhm added the bug Something isn't working label Mar 25, 2024
@hishamhm
Copy link
Member

Thanks for the report! This is definitely a bug that needs fixing.

return bar()

Is the goal here to trigger a tail call? It surprised me a bit which of the two options you marked as idiomatic — I usually never return f() from 0-ary functions, to help the reader spot that nothing is being returned.

@catwell
Copy link
Contributor

catwell commented Mar 25, 2024

I guess it varies but I tend to agree with @fperrad: I always return f() from 0-ary functions in Lua, in part because of the tail call.

@hishamhm hishamhm added the good first issue Good for newcomers label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants