Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: in some cases teal compiler cannot catch assign interface to record error. #925

Open
BLKTower opened this issue Feb 1, 2025 · 1 comment

Comments

@BLKTower
Copy link

BLKTower commented Feb 1, 2025

In simple case, the compiler can catch the error correctly:

local interface I
end
local record A is I
end
local function test(a: I): I
    return a
end
local i: I
local a: A
a = test(i) -- Error: I is not a A

But if the situation is more complex, the compile results become weird:

local interface I<T>
end
local record A1
end
local record A2 is I<A1>
end
local function test<T, K is I<T>>(a: T): K
    local k: K
    return k
end
local a1: A1
local a2: A2
local ia1: I<A1>
-- test 1
a2 = ia1 -- Error: I<A1> is not a A2
a2 = test(a1) -- No error, but it should?
-- test 2
ia1 = test(a1)
a2 = ia1 -- No error, but it should?
-- test 3
local z = test(a1)
a2 = z -- Error: I<A1> is not a A2

Desired behavior: teal compiler can catch the error.

@BLKTower
Copy link
Author

BLKTower commented Feb 1, 2025

And which makes me even more confused is if I do something like this:

local interface I<T>
end
local record A1
end
local record A2 is I<A1>
end
local record B1
end
local record B2 is I<B1>
end
local function test<T, K is I<T>>(a: T): K
    local k: K
    return k
end
local a1: A1
local b1: B1
local a2: A2
local b2: B2
a2 = test(a1)
local z = test(b1) -- From the type info json, z's type is I<A1>. Why?
b2 = z -- Error: I<A1> is not a B2. Why?

This makes no sense to me. Basically once I called test() , then all the following test() call will return the same type as the first call resolved, no matter what parameter I pass to the following test() calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant