andremm / typedlua

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

Lua file type can't be index-called #84

Closed Veltas closed 8 years ago

Veltas commented 8 years ago

Here is a minimal program using a file:

local input = io.open("test")

if input then
  local stuff = input:read("a")
  print(stuff)
  input:close()
end

This fails to compile on master (strict and non-strict modes):

filetest.tl:6:16: type error, attempt to index 'file' with 'read'
filetest.tl:8:2: type error, attempt to index 'file' with 'close'

The file type is defined in e.g. typedlua/lsl53/io.tld:

userdata file
  close : (self) -> (boolean?, string?, number?)
  flush : (self) -> (boolean)
  lines : (self, string|number*) -> (() -> (string|number*))
  read : (self, string|number*) -> (string|number*)
  seek : (self, string?, integer?) -> (integer) | (nil, string, integer)
  setvbuf : (self, string, integer?) -> (boolean) | (nil, string, integer)
  write : (self, string|number*) -> (self) | (nil, string, integer)
end

The compiler error is reported by check_invoke, on tlchecker.lua:1006.