jmid / luata-quickcheck Goto Github PK
View Code? Open in Web Editor NEWLua type analysis and corresponding QuickCheck code
License: BSD 2-Clause "Simplified" License
Lua type analysis and corresponding QuickCheck code
License: BSD 2-Clause "Simplified" License
It appears that the __metatable
field of a metatable is considered when resolving metamethods. (At least in Lua 5.1, 5.2 and 5.3) it is the case that __metatable
is only consulted when calling the getmetatable
built-in from Lua code. It is not consulted when resolving actual metamethods. It exists only as a protection mechanism for metatables, and not for overloading them from the point of view of Lua.
This discrepancy causes luata
to produce incorrect output for code using the __metatable
metamethod.
local complexMt = { __metatable = "Complex number metatable protected" }
local function Complex(real,imag)
local n = {real = real, imag = imag}
setmetatable(n, complexMt)
return n
end
function complexMt.__add(x,y)
return Complex(x.real + y.real, x.imag + y.imag)
end
function complexMt:__tostring()
return self.real .. "+" .. self.imag .. "i"
end
z = Complex(1,0) + Complex(0,2)
print(z)
Expected output
$ lua mytest.lua
1+2i
Hi!
I'm working on an editor plugin for Lua (atom-autocomplete-lua) and I would like to rewrite it using proper lattices. It would be really helpful to be able to use some of the code from this repo (especially the lexer and parser), but I can't do that because there is no license on this repo. Might you consider adding a LICENSE file? Maybe something permissive like the MIT license?
The analysis seems to be confident that c
is going to have a number
type instead of the actual nil
type. The analysis correctly identifies that the second return value might have number type (based on my understanding of the question mark) ? { number: Top }
however the analysis seems to give the wrong confidence to the type of b
with ! { number: Top }
local function f(x)
if x > 10 then
return 1,2
else
return 3
end
end
a,b=f(0)
c=type(b)
print(c)
Expected output:
$ lua mytest.lua
nil
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.