Godot 4.7 script error:not all control paths return a value

Godot Version

4.7

Question

the editor wont load most of the addons because not all control paths return a value.

func some_func(the_node:Node):
    if the_node:
        do_something()

is also not immune, i think it asks for a boolean return value. Most errors were for functions of the form:

func some_func(the_node:Node):
    if the_node:
        do_something()
        return the_node

is there a way to make the script compiler less pedantic?

It should not complain if the function return type is not declared

This isn’t a question of pedantic, it’s invalid code, you should return a value or not

Return null or something else in the rest of the cases, but this code doesn’t make any sense if you return something in some cases and not in others, what do you use the value for?

Yeah, it’s bad but still valid duck-typed code.

It’s not valid GDScript though

It compiles and runs, at least in 4.5:

extends Node

func foo(x):
	if x:
		return x
		
func _ready():
	print(foo(1))
	print(foo(0))

Output:

1
<null>

However, the compiler starts complaining once foo()'s return type is declared, even if it’s Variant. The following will result in compile time error:

func foo(x) -> Variant:
	if x:
		return x

That said, it’s extremely bad practice to do this. So always declare the return type and return it from all execution paths.

That’s probably a bug in 4.5, as per the documentation

4.7 appears to be behaving the same.

The docs say the default return value is null, so I guess that’s returned if there’s no explicit return statement or value.

1 Like

Im just testing godot 4.7… in godot 4.6 and 4.5 all the addons were working correctly.

Unfortunately a lot of addons have functions that do not declare a return type and functions that dont return a default value. These are breaking in 4.7 I dont want to modify them all because theres a risk of unintended behavior.

Even ‘set()’ functions that dont have a return type seem to cause the error message. The message says they should return bool, so perhaps thats the default?

Umm, as per the test I posted above, that error is caused by function having the declared return type, not by the lack of it. Try to test it yourself.

No error:

func foo(x):
	if x:
		return x
		

Error:

func foo(x) -> Variant:
	if x:
		return x
		

This isn’t specific to 4.7.
There’s something else that may be causing your addons to malfunction.

1 Like

I have moved the game back to 4.6 for now. I did start doing trivial corrections then i realized there might be more problems ahead, so i undid everything.

Never swap the engine version in the middle of the project development, especially not to a non-stable version. Unless, of course, there’s a feature you absolutely cannot live without :wink:

I wouldn’t say never. Depends on where you are at the project and what the changes are with the new version and how good you are with debugging things. Aside from new features, a new versions usually gives more stability and a later date for end of support.

It’s impossible to predict the ways the changes could break the project, even if you have the complete list of all the changes and in-depth understanding of them. Some of the breakage might not even manifest immediately. If the version was good enough for the project yesterday, it should be good enough tomorrow. Why risk the introduction of unknow number of potentially sneaky bugs.

Of course, for small throwaway projects it doesn’t really matter. The more serious the project, the more conservative should the engine upgrading strategy be. As the saying goes; if it ain’t broke, don’t fix it.

Yeah i think the problem is actually mostly the lack of return type in the function decleration.

How is that a problem if it doesn’t cause compile time errors, and is consistent between 4.6 and 4.7?

I have multiple applications for the paintable texture in 4.7, this could change the workflow and potentially save some memory compared to baked textures.

Ok i’ll run a rest using a typical addon, like dialogic … brb

I tried to upload a screenshot but the forum took too long trying to ‘process the upload’.

I made an empty in project in the recent

Godot_v4.7-dev1 and created an addons folder, then copied in the dialog addon. An error popped up and the project crashed.

When i reloaded there was an error on

func _get(property):

in the dialogic scripts. The function does not explicitly name the return type and not all control paths return a value.

That’s an implementation of a virtual function _get(). The return type is already declared to be Variant by the engine. This actually might be the difference in 4.7