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

StringName comparsion missing Array.has(String) and String in Array #63965

Closed
amatrelan opened this issue Aug 5, 2022 · 1 comment · Fixed by #68747
Closed

StringName comparsion missing Array.has(String) and String in Array #63965

amatrelan opened this issue Aug 5, 2022 · 1 comment · Fixed by #68747
Milestone

Comments

@amatrelan
Copy link

amatrelan commented Aug 5, 2022

Godot version

v4.0.alpha.custom_build [8f05263]

System information

Linux

Issue description

When using groups, now defined as StringName. So many functionalities have stopped working when comparing "value" (String). This comes apparent when there are places where String has been replaced by StringName, and there is no error that those aren't comparable. Also in the documentation, there is pointed out that those two (String, StringName) has compare operation.

Because there is no error in a wrong way to compare it causes problems, example wrong way to compare is:
"some" in get_groups(). This should raise an error if it's not comparable.

For clarification, I don't need those to work! But I would love to get error when those don't work as expected.
Ex error:
Array[StringName].has(Variant) Variant has to be same type as Array data, was String expected StringName

Steps to reproduce

  • Create empty project.
  • Add Node as root.
  • Add node to group some.
  • Add script with content on below
extends Node

func _ready():
	for each in get_method_list():
		if "test_" in each.name:
			print("%s returns %s" % [each.name, call(each.name)])

func test_one() -> bool:
	return "some" in get_groups()
		
		
func test_two() -> bool:
	for each in get_groups():
		if each == "some":
			return true
	return false
	
func test_three() -> bool:
	return get_groups().has("some")
	
func test_four() -> bool:
	for each in get_groups():
		match each:
			"some":
				return true
			_:
				return false
	return false

Output:

test_one returns false
test_two returns true
test_three returns false
test_four returns false

Minimal reproduction project

No response

@Calinou Calinou added this to the 4.0 milestone Aug 6, 2022
@Calinou Calinou moved this to To Assess in 4.x Priority Issues Aug 6, 2022
@TokisanGames
Copy link
Contributor

Test two and four are documented in #60145. This demonstrates issues with StringName conversion with in, has, and Node.get_groups().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants