teal-language / tl

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

0.15.1: incorrect redeclaration warning regression #620

Closed lewis6991 closed 1 year ago

lewis6991 commented 1 year ago

local record B
  contains : function(M, bufnr: integer, start: integer, last: integer): boolean
  on_lines : function(M, bufnr: integer, first: integer, last_orig: integer, last_new: integer)
  reset    : function(M)
end

local M: B = {}

function M:contains(bufnr: integer, start: integer, last: integer): boolean
end

function M:on_lines(_: integer, _: integer, _: integer, _: integer)
end

function M:reset()
end

Gives warnings:

teal/gitsigns/signs/vimfn.tl:84:1: redeclaration of function 'on_lines'
teal/gitsigns/signs/vimfn.tl:147:1: redeclaration of function 'contains'
teal/gitsigns/signs/vimfn.tl:156:1: redeclaration of function 'reset'

Changing to M.on_lines = function()... works around the issue.

hishamhm commented 1 year ago

@lewis6991 I couldn't reproduce the issue with the test case above. Could you double check the example? Thank you!

lewis6991 commented 1 year ago

Ok, the issue was quite a bit more nuanced. Here's a minimal reproducer:

base.tl:

local record M
  foo: function(M)
end

return M

t1.tl:

local B = require('base')

local M: B = {}

function M:foo()
end

return M

t2.tl:

local B = require('base')

local M: B = {}

function M:foo()
end

return M

top.tl:

local B = require('base')

local function new(cond: boolean): B
  local C: B
  if cond then
    C = require('t1')
  else
    C = require('t2')
  end
end

return new

Warning:

t2.tl:5:1: redeclaration of function 'foo'
hishamhm commented 1 year ago

@lewis6991 Thank you for the complete regression test! I pushed a fix.