@anon81993163 was right in 2 different posts…
you need rawget
for all indexes of self
, in the if-elseif statement and in the return statement because they all cyclically invoke the __index
metamethod. Here’s a fixed version:
--not sure what dynamic type <T> was for so removed it
function option:__index(key: any)
if (key == "is_some") then
return rawget(self, "__value") ~= math.huge + 1
elseif (key == "is_none") then
return rawget(self, "__value") == math.huge + 1
else
return rawget(self, key)
end
end