You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Food is only there to demonstrate that it isn't a base class issue,# but that the buck indeed stops with Fruit due to its defined _init.classFood:
varloadable:=falseclassFruitextendsFood:
varflying:=falsefunc_init():
pass# Berry is only there to demonstrate that the buck doesn't stop with# the parent class, but indeed is passed on to Fruit, since we don't# have an _init defined here.classBerryextendsFruit:
varexplody:=false# Since neither this class nor Berry have an _init defined, this will# be inferred as Fruit, not Melon.classMelonextendsBerry:
varextra_splashy:=false# Problem:# There is an _init defined in Fruit, but not in Melon or Berry, so this# is inferred by the editor as Fruit instead of Melon.varmelon:=Melon.new()
# This works, demonstrating that godot indeed understands this as `Melon`.print(melon.extra_splashy)
At runtime, melon behaves as expected, but in terms of properties the editor's code completion only offers loadable (from grand grand parent Food) and flying (from grand parent Fruit, which has _init) from the class hierarchy, but not explody (from parent Berry) or extra_splashy (Melon - itself). Every subclass in the hierarchy past Fruit, which is the one with _init, is ignored.
Also, when using VSCode the hover-tooltip shows Fruit as the type of melon, with the same above-described completion behaviour as in Godot's builtin editor.
What I'd expect: That melon is type-inferred as Melon, not Fruit.
Steps to reproduce
The minimal reproduction project contains bug.gd, which has three sets of classes and corresponding examples in _ready. The first set demonstrates how no _init in the parent leads to correct type inference, the second demonstrates the problem using the Fruit example, and the third is a bit superfluous, but shows a parent and subclass who both have _init defined, which works as expected.
A few lines are dedicated for uncommenting for easy experimenting, with comments explaining what to do.
The project can be run in order to observe the runtime behaviour of the Fruit example. It should print: This melon is extra splashy: false, demonstrating how a Melon object which is inferred as Fruit indeed has the extra_splashy property of Melon, despite not showing up in the code completion drop-down.
Calinou
changed the title
Editor type-infers closest parent with defined _init instead of the class itself
GDScript 2.0: Editor type-infers closest parent with defined _init instead of the class itself
Dec 27, 2022
Godot version
v4.0.beta10.official [d0398f6]
System information
Ubuntu 20.04, Ryzen 2700X, GTX 1070
Issue description
Basic example code:
At runtime,
melon
behaves as expected, but in terms of properties the editor's code completion only offersloadable
(from grand grand parentFood
) andflying
(from grand parentFruit
, which has_init
) from the class hierarchy, but notexplody
(from parentBerry
) orextra_splashy
(Melon
- itself). Every subclass in the hierarchy pastFruit
, which is the one with_init
, is ignored.Also, when using VSCode the hover-tooltip shows
Fruit
as the type ofmelon
, with the same above-described completion behaviour as in Godot's builtin editor.What I'd expect: That
melon
is type-inferred asMelon
, notFruit
.Steps to reproduce
The minimal reproduction project contains
bug.gd
, which has three sets of classes and corresponding examples in_ready
. The first set demonstrates how no_init
in the parent leads to correct type inference, the second demonstrates the problem using the Fruit example, and the third is a bit superfluous, but shows a parent and subclass who both have_init
defined, which works as expected.A few lines are dedicated for uncommenting for easy experimenting, with comments explaining what to do.
The project can be run in order to observe the runtime behaviour of the Fruit example. It should print:
This melon is extra splashy: false
, demonstrating how aMelon
object which is inferred asFruit
indeed has theextra_splashy
property ofMelon
, despite not showing up in the code completion drop-down.Minimal reproduction project
subclass_init_infer_bug.zip
The text was updated successfully, but these errors were encountered: