Finally! All the code I’ve written using
table.insert(t, v) is no longer inferior!
Finally! All the code I’ve written using
Does this mean we have to rescript our games or does the Customized Lua still work?
I feel like these recaps need something like:
THIS DOES NOT BREAK EXISTING CODE
Luau type annotations are purely optional
Right at the top of the post to stop people panicking that their game will suddenly need re-scripting.
Awesome sauce! Can’t wait to see more coming to this language!
It looks like there was a major regression with inferred types/generic functions, cause now I’m getting lots of warnings where an exported type (
Finalizer.Finalizer) is failing type relation with… itself.
Finalizer.newliterally returns an object of the exported type
I’ve created a repro:
GenericsRegression.rbxl (23.7 KB)
Removing “AddTask” from my exported type seems to fix this issue, so I’m guessing there’s a problem with relating a generic function to itself.
EDIT: here’s a simplified repro demonstrating the same issue:
--!strict type MyFunc = <T>(T) -> T local function returnsMyFunc(): MyFunc return function<T>(t: T) return t end end local f: MyFunc = returnsMyFunc()
Ah yes, this is a restriction of the current implementation: function types can’t return generic functions or take them as arguments. The error message isn’t much use here sorry.
You’re kidding me, right?
So… what am I supposed to do here? I have old code that used to function that is now not functioning because of this limitation that used to not be a limitation. Am I supposed to scrap my old code? Or am I supposed to code through 25 warnings in my codebase until some distant day in the future that this gets fixed?
Here’s a version of that repro for code that used to work which now doesn’t work by the way:
--!strict type MyFunc = typeof(function(t) return t end) local function returnsMyFunc(): MyFunc return function(t) return t end end local f: MyFunc = returnsMyFunc()
You say “Restriction”, I say “Regression that is impeding my workflow”
I suppose I’ve come up with a workaround, but it’s pretty much reduced a lot of type safety that used to exist in my codebase.
If I type my “AddTask” function as
(Finalizer, any) -> any instead of
<T>(Finalizer, T) -> T (Used to be typed as
typeof(function(t) return t end) before this update), I won’t get any warnings…
Except now whenever I use the
AddTask expressions in my code, I also don’t get proper type inference anymore, because everything this function returns is now typed as
circleButton variable used to be typed as CircleButton. Now, if I use the workaround, it gets typed as
This is a regression. I don’t want to have to wait a number of months for this to be fixed because it’s not considered a bug, but just a “restriction”.
I haven’t tried it, but shouldn’t it be just this?
type MyFunc<T> = (T) -> T
In general I just avoid adding type information to complex code, luau hasn’t come far enough to use in large projects for things like OOP or complex patterns…
any as a temporary workaround; we’re going to investigate this and come back after the break.
We had to revert the change to generic functions anyhow. I think this should solve your issue - please confirm if you get a chance.
Will there be inherent syntax for classes? Writing bunch of metatables can get tedious. Also introduces implicit features, but I don’t think that is possible to change.
global keywords like keyof, implements, extends, interfaces, are those going to be implemented?
On the topic of globals, what about declaring global types.
Will there be inherent syntax for classes?
Yes, it’s in our long-term roadmap - eventually it will be there. No details as of yet.
We discourage the use of globals; it’s not very likely that we’ll introduce first-class support for global types, although there’s a tangentially related feature that might see the light of day at some point.
Generics using the old syntax seem to be working now, thanks! Sorry about my tone earlier, just a little annoyed that it seemed like this bug wasn’t going to be addressed because it wasn’t considered to be a supported feature yet or something.
I don’t know enough details, the timing here is a bit unfortunate since we literally have a week-long spring break starting tomorrow but when we get back we will look at your specific use case, I’m reasonably sure we can make it work - we just didn’t realize before that it’s a use case that was important to keep working and there were some challenges with the first-class support of generics which was why it got broken. But we’ll try to make it work.
Is typechecking for functions safe? Can we start implementing this? Because I see you guys wrote this feature had bugs (or is it the typechecking+generics)
Some more questions: what’s gonna happen when you try and pass an object/type that is not the object/type the function specifies? Does it throw an error? Does it stop the script?
Also on your git generics are only primitives(???), what does it mean? That it won’t be able to check objects we write? I think if you go with generics it should be able to check for objects/classes/attributes.
On another note, I think GetAllAtributes that were set by players should be a function and could work very well with generics if an object has the same attributes as another for example (not the value of them, but the attributes themselves).
Wait, so you can make your own programming language?
Yes, the Luau Type Checking doesn’t break any scripts, it’s there to help the developer.
No, the script simply warns you in the editor that you’re using the incorrect type (which creates visual noise to get your attention).
Ahem. ^^ .This post earlier answers your question
yeah its actually not too hard once you understand the basics.
Oh you’re right I’m so sorry I thought the example needed the new syntax. You can recreate it using typeof.
This is going to be a tricky issue to solve, as backwards compatibility means supporting examples like this of functions returning generic functions that come about due to typeof. Thanks for providing the example, and I’m sorry I didn’t realize its impact yesterday.
In the mean time we’ve switched off the new generic function types, hopefully we’ll be able to reenable them once the issues are sorted out.