Skip to content

[BUG] Templates are messing everything up!! #276

@xDGameStudios

Description

@xDGameStudios

I have the following code.

namespace godot {

	class Vertex : public Reference {
		GODOT_CLASS(Vertex, Reference);

		public:
			void _init() {}
			static void _register_methods() {}

			Vertex() { Godot::print("Construct"); }
			~Vertex() { Godot::print("Destruct"); }
	};

	class ListDigraph : public Reference {
		GODOT_CLASS(ListDigraph, Reference);

		public:
			template<class T>
			Ref<T> __add_vertex() {
				return Ref<T>::__internal_constructor(T::_new());
			}

			virtual Ref<Vertex> add_vertex() { return __add_vertex<Vertex>(); }

			void _init() {}
			static void _register_methods() {}

			ListDigraph() {}
			~ListDigraph() {}
	};


/////////////////////////////////////////////////////////////////////////


	class PropertyVertex : public Vertex {
		GODOT_SUBCLASS(PropertyVertex, Vertex);

		public:
			void _init() {}
			static void _register_methods() {}

			PropertyVertex() {}
			~PropertyVertex() {}
	};

	class PropertyGraph : public ListDigraph {
		GODOT_SUBCLASS(PropertyGraph, ListDigraph);

		public:
			Ref<Vertex> add_vertex() override { return __add_vertex<PropertyVertex>(); }

			void _init() {}
			static void _register_methods() {}

			PropertyGraph() {}
			~PropertyGraph() {}
	};

}

Code compiles OK the problem is in the GDScript API:

	var g = ListDigraph.new()
	print(g.add_vertex())
	
	# Oututs
	#Construct
	#[Reference:1137]
	#Destruct

	var p = PropertyGraph.new()
	print(p.add_vertex())
	
	# Oututs
	#[Reference:1140]

even though "PropertyVertex" is a "Vertex" its construct and destruct code are not printed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions