Match and array matching - bug?

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Did I just found error in GdScript? It is in match with array matching:

func generate_as_only_part(dict : Dictionary) -> bool:
	for k:String in dict.keys():
		match k:
			["generate_as", "generate_as_front", "generate_as_back"] :  # it should be matched here
				continue
			_:
				pass
		if k[0] == "_":
			continue
		return false # but instead it goes here
	return true

image

As you can see we have “generate_as” in the dict, and k == “generate_as” but it is not matched and goes past the match block

you static typed ‘k’ as String, but you matching it with array. It will produce error if key not a String even before match part.
better replace to

if k in ["generate_as", "generate_as_front", "generate_as_back"]:continue

match used to check with exact values, if to check expressions

1 Like

Ok, looks like I didn’t understand correctly array matching. Thought it matches with any element of array