Skip to content

Variables can be used as function arguments of the wrong type #1229

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

Open
Pikachu920 opened this issue May 1, 2018 · 10 comments · May be fixed by #7892
Open

Variables can be used as function arguments of the wrong type #1229

Pikachu920 opened this issue May 1, 2018 · 10 comments · May be fixed by #7892
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something. PR available Issues which have a yet-to-be merged PR resolving it priority: low Issues that are not harmful to the experience but are related to useful changes or additions.

Comments

@Pikachu920
Copy link
Member

on script load:
  set {_test} to "a string"
  test({_test})

function test(player: player):
  broadcast "%{_player}% is {_player}"

test should never be called, but because null values are now accepted, it will get called with null

@bensku
Copy link
Member

bensku commented May 2, 2018

Seems to be working as intended. Variables are not type-safe. Does this occur if you directly give the expression as function parameter?

It is a bit stupid that even local variables do not remember their types. Changing that would probably be a good idea. But separate issue for that, if needed.

@Pikachu920
Copy link
Member Author

Pikachu920 commented May 2, 2018

This is certainly not intended behavior. It is a side effect of Converters#convert returning null if conversion fails or is not possible -- what used to be stopped because of the null prevention is now allowed to go through. Obviously, variables do not have a known type at parse time, however this is actually a runtime issue where the type can be derived.

@bensku
Copy link
Member

bensku commented May 3, 2018

Why do you think that it is not intended behavior? It is not like function parameters would have wrong types; they are just not available.

Of course, this could lead to cryptic errors. So could not calling the function do. In this case, you can at least add debug messages inside the function to check what parameter has trouble.

@Pikachu920
Copy link
Member Author

because if i call a function with the wrong type it shouldnt be called...

@bensku
Copy link
Member

bensku commented May 4, 2018

I'm not sure where you have got that idea. Other syntax elements are called, too, and may cause unpredictable effects when you mistype variables. Having functions work that way and not silently do nothing seems to make most sense.

I think current default is lesser evil: your function is always called when you ask for that. You don't need to consider that it might have not been called at all while debugging.

Making local variables know their type should be possible. It would at least partially solve this issue and generally be helpful.

@bensku bensku added enhancement Feature request, an issue about something that could be improved, or a PR improving something. priority: low Issues that are not harmful to the experience but are related to useful changes or additions. labels May 4, 2018
@Syst3ms
Copy link
Contributor

Syst3ms commented May 4, 2018

This "issue" is just the direct consequence of variables being dynamically typed. Yes, pretty much nothing is type-safe. But that's part of Skript's design, and dynamic typing in general. If you don't like it, then go ahead and make variables statically typed. But I don't think this is very good in Skript.

@Pikachu920
Copy link
Member Author

no, other syntax elements are not called. if at runtime your syntax is given the incorrect type it will not be called.

@Syst3ms
Copy link
Contributor

Syst3ms commented May 5, 2018

Well, it could just achieve the same effect in case none of the elements inside the function actually runs.
Imo this entire situation is more of an edge case, so honestly, any is good.

@TheLimeGlass TheLimeGlass self-assigned this Feb 1, 2022
@TheLimeGlass
Copy link
Contributor

TheLimeGlass commented Feb 1, 2022

I thought functions weren't erroring at all for incorrect types. It's just variables and in my case player but console was executing the command. Too ambiguous to be doing right now. Unassigning. A runtime error could be implemented to let the scripter know. Functions already have some runtime errors implemented.

@TheLimeGlass TheLimeGlass removed their assignment Feb 2, 2022
@TheLimeGlass
Copy link
Contributor

Related #3864

@TheLimeGlass TheLimeGlass changed the title Recent function changes break function type safety Variables can be used as function arguments of the wrong type Aug 15, 2022
@TheLimeGlass TheLimeGlass added the PR available Issues which have a yet-to-be merged PR resolving it label Feb 17, 2023
@APickledWalrus APickledWalrus linked a pull request May 23, 2025 that will close this issue
@APickledWalrus APickledWalrus moved this to In Progress in 2.12 Release Jun 4, 2025
@APickledWalrus APickledWalrus linked a pull request Jun 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something. PR available Issues which have a yet-to-be merged PR resolving it priority: low Issues that are not harmful to the experience but are related to useful changes or additions.
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

4 participants