stein197/lua-string

Type mismatch in function mt:__mul(n)

yaSebastian opened this issue · 1 comments

When looking through the code, Lua Diagnostics states the following type mismatch on the following line of code in function mt:__mul(n):

Annotations specify that return value # 1 has a type of string, returning value of type number here instead.

  • number cannot match string
  • Type number cannot match string
return n * self

Also, I'm still quite inexperienced in Lua, so please have my apologies if this is a really stupid question, but in the following code, shouldn't it be impossible for self to be a number? As far as I understand, __mul(n) would always be called on a string, unless someone applies either the metatable to another table or the function to another metatable, in which cases you'd have to check against a plethora of other conditions as well.

if type(self) == "number" then
	return n * self
end