Closed Balint66 closed 2 years ago
Ah, this looks like a bug that is fixed (or partially fixed) inside this long PR, because during my testing some of the behavior changes if you rename <T>
to <U>
in the definition of :of
(though it doesn't really fix it on master
). This is a tricky one to fix!
Be mindful though, that as far as Teal is concerned, T | nil
is not a more specific type than T
, since every type accepts nil
.
Thanks for the fast reply!
Actually, I know that T | nil
is not more specific than T
, it's there for readability and for those who are not used to Lua and has some other language background because who would guess that .T
as a specific type could be nilable? Where did my integer
go?
I'll have a fast look at the PR, although I tried to rename my generic variable in :of
from T
to K
, but it produced the same error for me.U
is used elsewhere in the file, so just wanted to be extra safe here
I'll report back as soon as I can.
Just checked, and the same error come up with the PR and with the changed generic type name.
Actually, I know that T | nil is not more specific than T, it's there for readability and for those who are not used to Lua and has some other language background
My general advice is against that since it can be misleading, especially for those coming from other backgrounds. If they see a T | nil
here and a T
there, they'll assume that the latter cannot be nil, which isn't true.
Just checked, and the same error come up with the PR and with the changed generic type name.
Yeah, I tried something similar and ran into the same bug. Thanks for confirming. I do know that parts of that PR do improve things and I'll try to extract them and merge them in (even without variadic type variables), and hopefully I can address the issue while doing that.
This should be fixed in the latest master
! Please let me know if you run into other similar crashes.
Hello there!
I wanted to implement a record based on java8's Optional class, when I stumbled upon an interesting bug.
Here is the code that gives the error, when I called:
I've tried to call it like so:
At both cases, it gives an error like this:
The relevant code is this one:
My temporary solution to make my code build is to ignore typevars when testing the unions, then the second
and indeed, only one lefttype is tested is nil, that always returns null.So, my guess is that T somehow resolves to the union of T and nil, that will recurse forever.