-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
Re-add local variable type hints #5457
base: dev/feature
Are you sure you want to change the base?
Conversation
Also fixed #1229 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking excellent 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
); | ||
} | ||
|
||
private static final int CONFLICT = 1, INSTANCE = 2, CONJUNCTION = 3, START_EXPR = 4; | ||
private static final int CONFLICT = 1, INSTANCE = 2, CONJUNCTION = 3, START_EXPR = 4, LOCAL_TYPES = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time for this to become an enum I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we could just use a switch statement to assign the ScriptWarning value based on the parse mark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or some ordinal like:
int mark = parseResult.mark;
if (mark < 0 || mark >= Enum.values().length)
return false;
warning = Enum.values()[mark];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah this is already done in init. Could probably store the ScriptWarning we are suppressing and use that for the toString switch instead of the int constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of making it it's own type. This is user accessable, so making it a ClassInfo is just simplier for us to add new enums in the future.
I wasn't going to address this here, but I guess I can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do that too. You don't have to do it for this PR though
I remember one of the issues of local variable type hints being syntax like How does this PR deal with that issue? |
It doesn't, and it's not the end of the world either, it'll act without type hints still. Maybe a better implementation rather than listening to the set/add would be the listening in on the variable change in Variables.class. Would be able to add a JUnit async effect test once the JUnit pull request is merged. |
Listening for acceptsChanges might also not work, I've seen addons use Indeed it's not the end of the world, but it's annoying for a user to get a false positive warning, it may confuse them. Make sure to also test for code that changes Event (and thus local variables) within a structure, such as sections (newer and older impls of them). Also those that carry over local variables from another event (e.g. spawn section of Skript) |
Ok, well I applied type hints when the change method of the variable expression is used. If an addon does not properly use the change method we cannot provide type hints for it. I don't want to be re-parsing a VariableString to check if it's simple in the Variables.setVariable method. |
NOTE: It should be failing. I have to update those tests to correct them now. |
This comment was marked as outdated.
This comment was marked as outdated.
bd134d0
to
3f08853
Compare
Description
Re-adds local variable type hints. This allows Skript to understand local variable types in some circumstances, and provide warnings so the user knows nothing will happen. Like setting a variable to a string and then attempting to teleport the player to the string should produce a warning.
Also made calling functions with local variables of the wrong type error #1229
Considering this breaking change I guess, since some users may not know their scripts aren't working.
Examples of proper warning now:
Notes:
Target Minecraft Versions: any
Requirements: none
Related Issues: #1229, #3864 and #5060