Closed User9684 closed 2 months ago
Assigning (A, B?) -> C
to (A) -> C
is always valid as all invocations of (A) -> C
are also valid invocations of (A, B?) -> C
since there is guaranteed not to be a second argument. It is still probably worth having a warning on the function as the number of arguments are known, though.
Since you type casted Test2Impl
to a different type, Luau has no idea that your "Test" function technically accepts a second argument, it only knows that Test2.Test
does not accept a second argument and so it wouldn't be type safe to pass one.
Yep, this is not a bug. The type of Test2Impl:Test
is compatible with the type you gave it like @Fireboltofdeath explained, and the second call is correctly erroring based on the interface you typed the function at (saying that it does not have an optional argument).
Hi, I was writing basic typed functions earlier and accidentally came across this, unsure if it's considered a bug or not, but it definitely seemed like a bug to me.
I've made two examples, one that has no issues and another that has a warning.
Example one, everything is typed correctly and there are no warnings as expected.
Example two, the function is defined with an argument that does not exist on the type, leading to a warning.
Expected behavior: Warning shows up on the function definition stating that
(self, arg1, arg2?)
cannot be converted into(self, arg1)
Actual behavior: Warning shows up on the secondTest
call saying that there are three arguments when expected only two.