Skip to content

Reflecting doesn't auto-convert from i64 to isize #18793

Open
@anlumo

Description

@anlumo

Bevy version

git main branch

What you did

Example code:

use bevy::{
    reflect::{DynamicStruct, ReflectFromReflect, TypeRegistry},
    render::camera::Camera,
};

fn main() {
    let mut type_registry = TypeRegistry::default();
    type_registry.register::<Camera>();

    let rfr = type_registry
        .get_type_data::<ReflectFromReflect>(std::any::TypeId::of::<Camera>())
        .unwrap();

    let mut dyn_struct = DynamicStruct::default();
    dyn_struct.insert("order", 4isize);
    let camera = rfr.from_reflect(&dyn_struct).unwrap();
    let camera = camera.downcast_ref::<Camera>().unwrap();
    assert_eq!(camera.order, 4);
    eprintln!("Assert with isize passed");

    let mut dyn_struct = DynamicStruct::default();
    dyn_struct.insert("order", 4i64);
    let camera = rfr.from_reflect(&dyn_struct).unwrap();
    let camera = camera.downcast_ref::<Camera>().unwrap();

    assert_eq!(camera.order, 4);
    eprintln!("Assert with i64 passed");
}

What went wrong

Output:

Assert with isize passed

thread 'main' panicked at src/main.rs:26:5:
assertion `left == right` failed
  left: 0
 right: 4

I assume that the same issue exists for usize/u64, but I haven't actually checked. I also don't think that this is related to the Camera component specifically, I just ran into the problem with that component.

Additional information

I'm very well aware that isize is not i64, but for all purposes, it is equivalent on 64 bit machines. I don't think that many scripting languages can differentiate between these two types, so not autoconverting makes the whole thing unnecessarily complicated for a lot of use cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behaviorC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-ContentiousThere are nontrivial implications that should be thought through

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions