andremm / typedlua

An Optional Type System for Lua
563 stars 53 forks source link

Prevent automatic variadic tails in strict mode #83

Closed Veltas closed 8 years ago

Veltas commented 8 years ago

Fixed problem with varlist/explist incompatibility from first attempt at https://github.com/andremm/typedlua/pull/82

Reasoning in previous pull request, once again I'm aware this may be too extreme a change, although I hope at this stage the project is flexible enough to either merge this or get the factorial example to work in another way in strict mode.

mascarenhas commented 8 years ago

I cannot look into this right now, but will have time later today. Strict mode should be the default, and it has no influence in how typechecking is done. The only thing that strict mode changes is the "variadic tail" in the input type of non-variadic functions, from nil* to value*, and not change output types at all. An input type of (t1, ..., tn) in strict mode is just syntax sugar for (t1, ..., tn, nil*), while in non-strict mode it is sugar for (t1, ..., tn, value*), while (t1, ..., tn) in the output type, or in an expression list, is always syntax sugar for (t1, ..., tn, nil*).

@andremm, any idea on why this is not working as it should?

Veltas commented 8 years ago

Thanks for looking into this! I thought there'd be a better fix.

I imagine this has gone on like this is because the type of return x is (something, nil*), so the deduced return type in strict mode will have the tail. It's not until you specify the function output type that it goes wrong.

I shall carry on trying to use this software in strict mode, and will complain/PR about anything else that seems wrong!

mascarenhas commented 8 years ago

Thanks! We should make strict the default, and maybe even deprecate non-strict mode, or at least make it a module-scoped pragma instead of a global option.

I have removed the nil* tails from printed error messages in the latest commit, so you can get nice error messages in strict mode, without all the nil*.