Skip to content

Commit 8d2268c

Browse files
committed
Test concrete remote generic
1 parent 7ca255c commit 8d2268c

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

crates/bevy_reflect/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,31 +1343,38 @@ bevy_reflect::tests::should_reflect_debug::Test {
13431343
fn should_reflect_nested_remote_type() {
13441344
mod external_crate {
13451345
pub struct TheirOuter<T> {
1346-
pub inner: TheirInner<T>,
1346+
pub a: TheirInner<T>,
1347+
pub b: TheirInner<bool>,
13471348
}
13481349
pub struct TheirInner<T>(pub T);
13491350
}
13501351

13511352
#[reflect_remote(external_crate::TheirOuter<T>, FromReflect)]
1352-
struct MyOuter<T: FromReflect> {
1353+
struct MyOuter<T: Reflect> {
13531354
#[reflect(remote = "MyInner<T>")]
1354-
pub inner: external_crate::TheirInner<T>,
1355+
pub a: external_crate::TheirInner<T>,
1356+
#[reflect(remote = "MyInner<bool>")]
1357+
pub b: external_crate::TheirInner<bool>,
13551358
}
13561359

13571360
#[reflect_remote(external_crate::TheirInner<T>, FromReflect)]
1358-
struct MyInner<T: FromReflect>(pub T);
1361+
struct MyInner<T: Reflect>(pub T);
13591362

13601363
let mut patch = DynamicStruct::default();
13611364
patch.set_name("MyOuter".to_string());
1362-
patch.insert("inner", MyInner(external_crate::TheirInner(321)));
1365+
patch.insert("a", MyInner(external_crate::TheirInner(321)));
1366+
patch.insert("b", MyInner(external_crate::TheirInner(true)));
13631367

13641368
let mut data = MyOuter(external_crate::TheirOuter {
1365-
inner: external_crate::TheirInner(123),
1369+
a: external_crate::TheirInner(123),
1370+
b: external_crate::TheirInner(false),
13661371
});
13671372

1368-
assert_eq!(123, data.0.inner.0);
1373+
assert_eq!(123, data.0.a.0);
1374+
assert!(!data.0.b.0);
13691375
data.apply(&patch);
1370-
assert_eq!(321, data.0.inner.0);
1376+
assert_eq!(321, data.0.a.0);
1377+
assert!(data.0.b.0);
13711378
}
13721379

13731380
#[test]

crates/bevy_reflect_compile_fail_tests/tests/reflect_remote/nested.fail.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,18 @@ mod mismatched_remote_type {
4545
struct MyInner<T: Reflect>(pub T);
4646
}
4747

48+
mod mismatched_remote_generic {
49+
use bevy_reflect::{reflect_remote, Reflect};
50+
51+
#[reflect_remote(super::external_crate::TheirOuter<T>, FromReflect)]
52+
struct MyOuter<T: Reflect> {
53+
// Reason: `TheirOuter::inner` is not defined as `TheirInner<bool>`
54+
#[reflect(remote = "MyInner<bool>")]
55+
pub inner: super::external_crate::TheirInner<bool>,
56+
}
57+
58+
#[reflect_remote(super::external_crate::TheirInner<T>, FromReflect)]
59+
struct MyInner<T: Reflect>(pub T);
60+
}
61+
4862
fn main() {}

crates/bevy_reflect_compile_fail_tests/tests/reflect_remote/nested.fail.stderr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,16 @@ error[E0308]: mismatched types
6666
= note: expected struct `TheirInner<T>`
6767
found struct `TheirOuter<T>`
6868
= note: this error originates in the attribute macro `reflect_remote` (in Nightly builds, run with -Z macro-backtrace for more info)
69+
70+
error[E0308]: `?` operator has incompatible types
71+
--> tests/reflect_remote/nested.fail.rs:51:5
72+
|
73+
51 | #[reflect_remote(super::external_crate::TheirOuter<T>, FromReflect)]
74+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found `bool`
75+
52 | struct MyOuter<T: Reflect> {
76+
| - this type parameter
77+
|
78+
= note: `?` operator cannot convert from `TheirInner<bool>` to `TheirInner<T>`
79+
= note: expected struct `TheirInner<T>`
80+
found struct `TheirInner<bool>`
81+
= note: this error originates in the attribute macro `reflect_remote` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)