andremm / typedlua

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

attempt to index '(string)' with '"gsub"' #106

Open Zash opened 7 years ago

Zash commented 7 years ago
local function a(s:string):string
  return (s:lower():gsub("a","b"));
end

should be equivalent to string.gsub(s:lower(), "a", "b") and string.gsub(string.lower(s), "a", "b") but gives a type error.

Veltas commented 7 years ago

You're right; there appears to be a bug in the compiler for the : operator.

As a workaround, it works when you wrap the first member-call in brackets (although this should make no difference to Lua):

(s:lower()):gsub("a", "b")
Veltas commented 7 years ago

This is a completely nonsense report, something is clearly broken here:

("a"):gsub("a", "b"):lower()
attempt to index '(string, integer)' with '"lower"'