Skip to content

as operator raises Parse Error and conversion failed even when corresponding constructor exists #107979

Open
@lethefrost

Description

@lethefrost

Tested versions

  • Reproducible in 4.4.1.stable

System information

Godot v4.4.1.stable - macOS Sequoia (15.5.0) - Single-window, 2 monitors - Metal (Forward+) - integrated Apple M2 Max (Apple8) - Apple M2 Max (12 threads)

Issue description

In the documentation, the as operator/keyword can be used to cast between built-in types. And in the same documentation, it gives the following snippet as an example:

var my_int: int
my_int = "123" as int # The string can be converted to int.
my_int = Vector2() as int # A Vector2 can't be converted to int, this will cause an error.

And the int built-in type does have a constructor that can construct from String, so "123" as int should work.

But in Godot 4.4.1.stable, any "123" as int raises Parse Error: Cannot cast a value of type "String" as "int", whereas int("123") works fine.

Image

Not yet noticed another case that a corresponding constructor exists but as keyword casting fails other than String as int.

Steps to reproduce

Try "123" as int

Minimal reproduction project (MRP)

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    For team assessment

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions