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

Type identifying where clause behaviour changes when using interfaces loaded via require #853

Open
svermeulen opened this issue Nov 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@svermeulen
Copy link
Contributor

local type A <const> = require("a")

-- local interface A
-- 	get_type: function(A): string
-- end

local type B <const> = require("b")

-- local interface B is A where self:get_type() == "b"
-- end

local b: A = {
	get_type = function(): string return "b" end
}

local c: A = {
	get_type = function(): string return "c" end
}

if c is B then
   print("is B")
else
   print("is not B")
end

The above code prints "is B" when it should print "is not B". If we stop using 'require' and place the contents of the files directly in the above code, then we correctly get "is not B". It seems that when included via files, the compiled lua code is this:

if type(c) == "table" then
   print("is B")
else
   print("is not B")
end

And when not using require it is this:

if c:get_type() == "b" then
   print("is B")
else
   print("is not B")
end
@hishamhm hishamhm added the bug Something isn't working label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants