godot: `match` statement performs strict type checking unlike `if`, causing it to fail unexpectedly when comparing String to StringName

Godot version

4.0 alpha5

System information

linux

Issue description

im trying to use “match” statement when an animation has finished. however it doesnt work anymore. print debug doesnt see the match of an animation name

an “if” statement does work however

Steps to reproduce

func _on_animation_player_animation_finished(anim_name):
		
	if anim_name == "Fire":
		isfiring = false
	
		
	match anim_name:
		"Fire":
			isfiring = false
			print_debug("no match, anim_name=", anim_name)`

Minimal reproduction project

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (9 by maintainers)

Most upvoted comments

i have no problem using an ‘if’ statement instead of match, i only posted it cause the syntax was changed

That’s fine, and I’m glad you have a solution. This is now no longer about your individual issue. It’s about a philosophical design choice in the language that needs to be worked out for all Godot game devs. So far about 6 people have expressed a desire for reverting the change and no people or reasons for keeping the new behavior.

Is there any logic behind match being more strict than ==? It seems kinda unintuitive. Do other languages do that?

I agree, it seems unintuitive.

it used to work fine in godot3.

Godot 3.x didn’t have a StringName type exposed to GDScript, so everything was a String – including anim_name in your example.

so this is the new syntax i should be using then?

Yes 🙂