GDscript strange behavior. A bug?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By z80


I’ve just run into a strange issue I believe might be a bug.

I’m adding the result returned by load() to an array. And it destroys the array in the case if it is null.

func gui_classes():
    var classes = []
    var C = load( "res://...." ) # Here C is null. I.e. path seems not being a valid one.
    classes.push_back( C ) # At this line "classes" variable changes type from an Array to Null. It is not an Array anymore, it is literally a Null.
    return classes # And returns null

But if I simply hardcode null:

func gui_classes():
    var classes = []
    var C = null
    classes.push_back( C ) # Now it is fine, classes = [null], an array with one null element.
    return classes # And returns an Array

It doesn’t seem to me it is an expected behavior. Right?

My Godot version is 3.2.2 built from source. Is it a bug or a feature?

:bust_in_silhouette: Reply From: njamster

I cannot confirm that. Both of your examples return an array! However, the former returns an array containing a null-object (created by load) and the latter returns an array containing a null-variable.