teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.04k stars 101 forks source link

Invalid type error #582

Closed svermeulen closed 1 year ago

svermeulen commented 1 year ago

When I type check the following with the latest version (098780f) I get an error that doesn't make sense:


local record Container
end

function Container.new(): Container
   return setmetatable({} as Container, { __index = Container })
end

function Container:try_resolve<T>(id:string):T
   if id == "foo" then
      return 5 as T
   end

   if id == "bar" then
      return "asdf" as T
   end
end

function Container:resolve<T>(id:string):T
   return self:try_resolve(id)
end

local container:Container = Container.new()
local foo:integer = container:resolve('foo')
local bar:string = container:resolve('bar')

print(foo)
print(bar)

It says "In local declaration: bar: got integer, expected string" on line local bar:string = container:resolve('bar'). It seems the type checking for the previous line bled over into the new line somehow

hishamhm commented 1 year ago

@svermeulen This should be fixed in master at last!