bevyengine / bevyengine/bevy

Reflecting doesn't auto-convert from i64 to isize

Open
#18,793 1 comment 0 reactions 0 assignees View on GitHub
A-Reflection C-Bug C-Usability S-Needs-Design X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

git main branch

## What you did

Example code:

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

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

let rfr = type_registry
.get_type_data::(std::any::TypeId::of::())
.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::().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::().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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.