Closed XmiliaH closed 3 years ago
Thank you - I will check it out.
As can be seen in the failed test I removed that #{} is a RAVI_TNUMINT and instead a RAVI_TANY since the metamethod could return anything. The inserted cast to integer didn't show the same behavior as puc lua.
Yes meta methods make type inference tricky. I forced #{} to int by adding a type assertion - mainly because it is useful for optimization in loops. I accepted the trade off that if user made # return non integer then it would be an error.
And I noticed that it is still compatible to lua, since lua code will not have the table annotated as table and the any case will return any.
Also note that meta methods are ignored by Ravi for integers / numbers when these are specialized. I should add this is for arithmetic/bit operations only.
The 'and' and '..' operators were left out - I guess inferring "" and 1
as 1
means we ignore meta-methods right?
There is no metamethod for 'and', 'or', 'not'. Also '..' will not call metamethods if both sides are numbers or strings as far as I know.
And I noticed that it is still compatible to lua, since lua code will not have the table annotated as table and the any case will return any.
Indeed the type assertion is only applied when we have explicit annotation that it is a table
Thank you for the contribution - much appreciated. If all tests pass - and I can also run Suravi tests then I will merge it. If I see issues I will get back. But I can only look properly over the weekend.
Hey, I'd like to redirect this PR to a branch so that I can test it before I merge to master
You can just check out the pull request locally as described in https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally.
Note that I did need to revert #("")
and "" .. 1
to RAVI_TANY since RAVI_TSTRING can be nil and nil might call metamethods.
Some improvements with type deduction.
Some examples