Skip to content

Godot 4.6: Parse Error: The variable type is being inferred from a Variant value, so it will be typed as Variant. #63

@hsandt

Description

@hsandt

In Godot 4.6 (and probably before, since the warning as error was introduced earlier), there is a warning treated as error by default on that line res://ldtk-importer/src/util/util.gd:24:

var data := JSON.parse_string(json.get_as_text())

This causes warning as error:

ERROR: res://ldtk-importer/src/util/util.gd:24 - Parse Error: The variable type is being inferred from a Variant value, so it will be typed as Variant. (Warning treated as error.)

which in turns triggers a chain of errors (but not relevant to us):

  ERROR: res://ldtk-importer/src/util/definition_util.gd:0 - Compile Error: Failed to compile depended scripts.
  ERROR: modules/gdscript/gdscript.cpp:2907 - Failed to load script "res://ldtk-importer/src/util/definition_util.gd" with error "Compilation failed".
  ERROR: Attempt to open script 'res://addons/ldtk-importer/src/components/ldtk-entity.gd' resulted in error 'File not found'.
  ERROR: Failed loading resource: res://addons/ldtk-importer/src/components/ldtk-entity.gd.

I fixed it locally by removing statically inferred type:

	# CHANGED: replaced `:=` with `=` to fix "Parse Error: The variable type is
	# being inferred from a Variant value, so it will be typed as Variant.
	# (Warning treated as error.)"
	var data = JSON.parse_string(json.get_as_text())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions