godot-console icon indicating copy to clipboard operation
godot-console copied to clipboard

No constructor of "int" matches the signature "int(null)".

Open amap1380 opened this issue 1 year ago • 3 comments

Godot version: Godot 4.0 beta 10 addon version: godot 4 branch 3b61520 running the project will result an error in IntType.gd Line 12

amap1380 avatar Dec 28 '22 08:12 amap1380

removing the int constructor will resolve the issue

amap1380 avatar Dec 28 '22 08:12 amap1380

Thanks for reporting! Will fix

quentincaffeino avatar Jan 13 '23 11:01 quentincaffeino

Removing the integer cast will make the code incorrect as the function is supposed to return an int.

There's something interesting i've just learned. GDScript's static analyzer can determine function's return type based on its code, return type specifier isn't necessary. Thus the following function will have return type of null:

# @param    Variant  value
# @returns  String|null
func _reextract(value):
	var rematch = self._regex.search(value)

	if rematch and rematch is RegExMatch:
		return rematch.get_string()
	
	return null
	

Which is the reason for this error. I got rid of the error by doing this instead:

	if rematch and rematch is RegExMatch:
		return rematch.get_string()
	else:
		return null

hilfazer avatar Jul 25 '23 13:07 hilfazer