Repository: godot
Issue: C++ module does not compile if binding a function that returns a class instance
Labels: bug,topic:core,needs testing

### Godot version

3.6 beta custom build

### System information

MX Linux 21.2 64-bit, Mesa Intel(R) Xe Graphics (TGL GT2)

### Issue description

When creating a C++ module where the class binds a function that returns a class instance, Godot gives a compilation error. This error is not given when not binding this function.

The error given:
```[ 28%] In file included from ./core/method_bind.h:383,
                 from ./core/class_db.h:34,
                 from ./core/reference.h:34,
                 from modules/breuk/breuk.h:4,
                 from modules/breuk/breuk.cpp:8:
./core/method_bind.gen.inc: In instantiation of 'PropertyInfo MethodBind2R<R, P1, P2>::_gen_argument_type_info(int) const [with R = Breuk; P1 = int; P2 = int]':
./core/method_bind.gen.inc:1644:23:   required from here
./core/method_bind.gen.inc:1645:60: error: incomplete type 'GetTypeInfo<Breuk, void>' used in nested name specifier
 1645 |   if (p_argument==-1) return GetTypeInfo<R>::get_class_info();
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
./core/method_bind.gen.inc: In instantiation of 'GodotTypeInfo::Metadata MethodBind2R<R, P1, P2>::get_argument_meta(int) const [with R = Breuk; P1 = int; P2 = int]':
./core/method_bind.gen.inc:1627:34:   required from here
./core/method_bind.gen.inc:1628:41: error: incomplete type 'GetTypeInfo<Breuk, void>' used in nested name specifier
 1628 |   if (p_arg==-1) return GetTypeInfo<R>::METADATA;
      |                                         ^~~~~~~~
[ 28%] ./core/method_bind.gen.inc: In instantiation of 'Variant MethodBind2R<R, P1, P2>::call(Object*, const Variant**, int, Variant::CallError&) [with R = Breuk; P1 = int; P2 = int]':
./core/method_bind.gen.inc:1656:18:   required from here
./core/method_bind.gen.inc:1681:36: error: conversion from 'Breuk' to non-scalar type 'Variant' requested
 1681 |   Variant ret = (instance->*method)(_VC(1), _VC(2));
      |                 ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
[ 29%] ./core/method_bind.gen.inc: In instantiation of 'void MethodBind2R<R, P1, P2>::ptrcall(Object*, const void**, void*) [with R = Breuk; P1 = int; P2 = int]':
./core/method_bind.gen.inc:1686:15:   required from here
./core/method_bind.gen.inc:1688:22: error: 'encode' is not a member of 'PtrToArg<Breuk>'
 1688 |   PtrToArg<R>::encode(  (instance->*method)(PtrToArg<P1>::convert(p_args[1-1]), PtrToArg<P2>::convert(p_args[2-1])) ,r_ret)  ;
      |   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 29%] ./core/method_bind.gen.inc: In instantiation of 'Variant::Type MethodBind2R<R, P1, P2>::_get_argument_type(int) const [with R = Breuk; P1 = int; P2 = int]':
./core/method_bind.gen.inc:1625:69:   required from 'Variant::Type MethodBind2R<R, P1, P2>::_gen_argument_type(int) const [with R = Breuk; P1 = int; P2 = int]'
./core/method_bind.gen.inc:1625:24:   required from here
./core/method_bind.gen.inc:1637:61: error: incomplete type 'GetTypeInfo<Breuk, void>' used in nested name specifier
 1637 |   if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;
      |                                                             ^~~~~~~~~~~~
```

The error in image form:
![foutmeldingGodotC++module1](https://user-images.githubusercontent.com/5214209/188859492-71c94251-4fd9-4c4e-947b-5677e287d73e.png)
![foutmeldingGodotC++module2](https://user-images.githubusercontent.com/5214209/188859479-4f56afa0-9a67-4ba3-8669-63c312acdc1c.png)

The piece of code that causes this error.
![maak](https://user-images.githubusercontent.com/5214209/188859459-4a03a522-324b-46e6-8c1c-87917a95f4cb.png)
![dezeverbindinggeeftdefout](https://user-images.githubusercontent.com/5214209/188859475-f1166339-8e59-44b7-9265-07fab4298b80.png)

The module that causes this error:[breuk.zip](https://github.com/godotengine/godot/files/9525239/breuk.zip)

### Steps to reproduce

1. Follow the steps on https://docs.godotengine.org/en/stable/development/cpp/custom_modules_in_cpp.html to create your own module. Alternatively, just take [breuk.zip](https://github.com/godotengine/godot/files/9525239/breuk.zip)
2. Now, in the class that you created, create a function that returns a class instance. This could be as in my example: ```Breuk Breuk::maak(int x, int y) { return Breuk(x, y); }```
3. Now bind this class in the **_bind_methods()** function of the class using **ClassDB::bind_method**. In my example: ```ClassDB::bind_method(D_METHOD("maak", "x", "y"), &Breuk::maak);```

Now go to the main folder of the cloned repository of Godot and run ```scons -j8 platform=x11``` to compile the project.

You will get a compilation error. This compilation error goes away when outcommenting the binding, or when modifying the bound function in such a way that it returns one of the default types (_integer, float, bool, string, char etcetera_) rather than return a class instance.

### Minimal reproduction project

This error is not occurring when Godot is running, but then Godot is compiling. Therefore, I hereby include the module that evokes this compilation error: [breuk.zip](https://github.com/godotengine/godot/files/9525239/breuk.zip)