Skip to content

Array<unsigned int> can hold signed values when converted from Variant #851

@Houtamelo

Description

@Houtamelo

While writing tests for the collections_to_variant PR, this test failed:

let wrong_slice_type = &[
        50,
        -10,
];

let err = wrong_slice_type
        .to_variant()
        .try_to::<Array<u32>>()
        .expect_err("should have wrongly typed slice");

The test panics at the last line .expect_err("should have wrongly typed slice") with the message:

-- rust_to_array_invalid ... [50ERROR: Rust function panicked at godot-core\src\meta\godot_convert\mod.rs:95.
  Context: itest `rust_to_array_invalid` failed
   at: godot_core::private::handle_panic_with_print (godot-core\src\private.rs:369)
ERROR: [panic]  FromGodot::from_variant() failed: `u32` cannot store the given value: -10
   at: godot_core::private::handle_panic_with_print (godot-core\src\private.rs:382)

Despite the slice having signed integers, Array::<u32>::try_from_variant is returning Ok, with signed integers inside.

If instead of expect_err, I unwrap then print:

let invalid_array= wrong_slice_type
        .to_variant()
        .try_to::<Array<u32>>()
        .unwrap();

print!("{invalid_array}");

It panics on print! since the fmt implementation assumes that the array only has unsigned integers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: duplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions