Match statements create an error in lambda functions

Godot Version

4.3 stable

Question

match statements create the error “Expected expression for match pattern.” when in a lambda function for no discernable reason

its easy to replicate. the code below will appear fine in the editor with no errors

match 0:
	0: pass

but the code below will create the error i mentioned

(func():
	match 0:
		0: pass)

i cant find anything about this online and dont see why it wouldnt work. if its my mistake any explanation would be appreciated

Just a wild guess but maybe pass in the context of a match is not considered an expression in the gdscript compiler.

the statement works fine outside of the lambda function, something like print() or other useful code still create an error. i appreciate your input though

I just tried this and it works no errors:

func _ready() -> void:
	var n = func(): 
		match 0: 
			0: print("test")
	n.call()

In fact it is the use of brackets that is causing your error:
This gives me your error:

func _ready() -> void:
	var n = (func(): 
		match 0: 
			0: print("test"))
	n.call()

I am thinking that this is a bug and cousin to this reported bug.
The error goes away if you move the closing bracket out of the match statement.
This reports no error:

func _ready() -> void:
	var n = (func(): 
		match 0: 
			0: print("test")
		)
	n.call()

I am going to post this as a reply to that bug. I now think it is the same bug.

1 Like