Skip to content
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

array.index_of: string argument got mistaken as function? #795

Open
juchiast opened this issue Dec 16, 2023 · 3 comments
Open

array.index_of: string argument got mistaken as function? #795

juchiast opened this issue Dec 16, 2023 · 3 comments
Labels

Comments

@juchiast
Copy link

let array = ["hello"];
array.index_of("hello");
EXCEPTION: Function not found: hello (&str | ImmutableString | String, i64)
in call to function 'index_of' (line 2, position 7)
@schungx
Copy link
Collaborator

schungx commented Dec 16, 2023

I believe index_of takes a closure that matches items.

If you put in a string, it looks up a script function of the same name.

Thats why it is looking for a function called hello.

@juchiast
Copy link
Author

There is an index_of that compares the passed value, only works with number

let array = [4, 5, 6, 19];
array.index_of(19);`

pub fn index_of(
ctx: NativeCallContext,
array: &mut Array,
value: Dynamic,
) -> RhaiResultOf<INT> {
if array.is_empty() {
return Ok(-1);
}
index_of_starting_from(ctx, array, value, 0)
}

@schungx
Copy link
Collaborator

schungx commented Dec 16, 2023

It works for all types except string, where it got mistaken as name of a function...

The versions with function names as strings are deprecated but not yet removed for fear of breaking scripts.

Therefore unfortunately the depreciated version override the standard generic version.

@schungx schungx added the bug label Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants