godot: Assigned type (Class) doesn't match the function argument's type (Class)

Godot 3.2 beta2

I am getting a strange error with typed GDScript, where it finds incompatibility between argument type and parameter type… while they are actually the same.

SCRIPT ERROR: GDScript::reload: Parse Error: At "update_episode_data_from_file()" call, argument 1. Assigned type (Project) doesn't match the function argument's type (Project).
          At: res://main.gd:294

I have a script_data.gd file with a Project class inside.

I also have a script_parser.gd file which const-imports the previous one, in order to define the following function:

const ScriptData = preload("./script_data.gd")
   ...
static func update_episode_data_from_file(project: ScriptData.Project, path: String) -> Array:
   ...

Then I const-imported both scripts inside main.gd, in which I have the following:

const ScriptData = preload("./script_data.gd")
const ScriptParser = preload("./script_parser.gd")
    ...
var _project : ScriptData.Project = null
    ...
func _open_project(fpath: String):
    ...
	var dir := fpath.get_base_dir()
	for ep_file_rpath in data.episode_files:
		var path := dir.plus_file(ep_file_rpath) as String
		ScriptParser.update_episode_data_from_file(_project, path)

This code works fine, but recently I’ve been getting this typing error in the editor, and it obscures any error happening elsewhere after this line… So far the only thing that fixes it is to close the editor and reopen it. Then a few hours later, it reappeared again. I tried to repro in a simpler project, but could not find a pattern yet…

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 8
  • Comments: 23 (4 by maintainers)

Commits related to this issue

Most upvoted comments

image It still happens on the 3.5 language server. Like @WarrenMarshall said, works fine during runtime, it’s just an annoying false positive.

@Azagwen are you sure this is the same error? Orientation is a global enum, does this happen if you name it something different?

Edit: Confirmed, this is caused by the fact that Orientation is already defined, this should probably instead be an error when defining an Enum that shadows a global name

“I don’t use inner classes, but I do use class_name, which seems to cause this as well. It happens at seemingly random places.”

Confirming. It just pops up for seemingly no reason in places. It doesn’t cause runtime problems so I’ve learned to just ignore it and live with it, but it’s annoying.

Although it’s marked as fixed, I’m getting the error again on 3.2. I believe the issue should be reopened. image image

That seems to be a bug in the shadowing warnings, please open a new issue for this, as the code works fine (minus the fact that you can’t make the const variables) once you fix that part

Still an issue in 3.4.2

I don’t use inner classes, but I do use class_name, which seems to cause this as well. It happens at seemingly random places. Quitting and reopening the project often makes the error disappear.

At other times I’ve had problems with inheritance. For example when class Child extends Parent and there’s a function that expects Parent, but I’m passing in Child, which should be fine, but Godot complains with Assigned type (Child) doesn't match the function argument's type (Parent).

Another workaround that does the job for me:

If this produces the error:

func doSomethingFunction(argument :MyInnerClass)
    var instance :MyInnerClass = argument # Doesn't match variable's type error

This solves it for me, via using a temporary typeless variable:

func doSomethingFunction(argument :MyInnerClass)
    var temp = argument
    var instance :MyInnerClass = temp # No error, works fine