Colon (:Method) defined methods not autofilling in specific usecase

In my game I have a generic Tool type which contains methods which all tools should have. I then have types for every specific tool (these do not inherit Tool, but share the same methods). When using the programming pattern shown in the screenshot below, all : methods will not autocomplete.
image

Another bug that is probably related: In my game . and : functions seem to be flipped (when using Sword: new appears as a valid method, but not the others), but I can’t figure out how to reproduce this behaviour, I will provide the types and involved functions below:

Generic Tool Type:
image

Server Firearm Type:

Function where this issue is occuring:

GetPlayerEquipped function:

Expected behavior

I expect for the methods to show correctly.

With all of these examples you show, you are not verifying that the returned value is not nil.

Every type that you’ve showcased is simply “T?”. You need to further refine that type down to “T” by first checking that the type isn’t nil before trying to use it. Once that is done the autocomplete for self-notated functions will work.

You have to look at it this way, all the self-notated methods you have REQUIRE that the self argument be of type “T”, but you are trying to pass in type “T?”, so they aren’t going to show up.

The only reason why your “new” function shows up is because “Tea” is set to the type “any”. So the type “T?” matches that. Remember, dot-notation is simply just doing this conversion for you:

Class:Test(...)
to
Class.Test(Class, ...)

So, for your “new” function, you are basically saying that the first argument can by of “any” type. And when you use self-notation (dot-notation), any type you are using it on will work in this instance.

So, Luau is working correctly. Should they be more clear as to why this is happening? Absolutely, but the logic behind it isn’t wrong.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.