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

record fields declared with self type don't get properly type checked #846

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

Comments

@FractalU
Copy link
Contributor

FractalU commented Nov 1, 2024

The following example code erroneously passes.

local record Struct<T>
	a: T
	b: T
	c: self
end

local a: Struct<integer> = {
	a = 1,
	b = 2,
	c = 3,
}

print(a.a, a.b, a.c)

If in the example code the self type gets replaced with Struct<T> then the following error message gets produced.

1 error:
self.tl:10:6: in record field: c: got integer, expected Struct<integer>
----------------------------------------
1 error

The same happens if the self type is inside a function. Here with a similar example.

local record Struct<T>
	a: T
	b: T
	c: function<T>(self)
end

local a: Struct<integer> = {
	a = 1,
	b = 2,
	c = function(a: integer) end,
}

print(a.a, a.b, a.c)

This example also erroneously passes with some warnings. If the self type gets replaced with Struct<T> then the following error message gets produced.

========================================
2 warnings:
self.tl:4:14: type argument shadows previous declaration of 'T'
self.tl:10:15: unused argument a: integer
----------------------------------------
2 warnings
========================================
1 error:
self.tl:10:18: in record field: c: argument 1: got integer, expected Struct<T>
----------------------------------------
1 error

@hishamhm hishamhm added the bug Something isn't working label Nov 1, 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