Skip to content

Commit 56fbb4c

Browse files
bors[bot]chitoyuu
andauthored
Merge #1012
1012: Fix FromVariant impls using get_type to test for Nils r=chitoyuu a=chitoyuu As of #1002, it has been discovered that more than one representations for Nil can exist, and such tests should be carried out using `is_nil()` instead. Co-authored-by: Chitose Yuuzaki <chitoyuu@potatoes.gay>
2 parents a2a85e1 + 702f933 commit 56fbb4c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

gdnative-core/src/core_types/variant.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ impl fmt::Debug for Variant {
643643
godot_test!(
644644
test_variant_nil {
645645
let nil = Variant::nil();
646-
assert_eq!(nil.get_type(), VariantType::Nil);
647646
assert!(nil.is_nil());
648647

649648
assert!(nil.try_to::<VariantArray>().is_err());
@@ -1041,7 +1040,14 @@ impl ToVariantEq for () {}
10411040
impl FromVariant for () {
10421041
#[inline]
10431042
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError> {
1044-
variant.try_as_sys_of_type(VariantType::Nil).map(|_| ())
1043+
if variant.is_nil() {
1044+
return Ok(());
1045+
}
1046+
1047+
Err(FromVariantError::InvalidVariantType {
1048+
variant_type: variant.get_type(),
1049+
expected: VariantType::Nil,
1050+
})
10451051
}
10461052
}
10471053

@@ -1440,9 +1446,14 @@ impl<T> ToVariantEq for std::marker::PhantomData<T> {}
14401446
impl<T> FromVariant for std::marker::PhantomData<T> {
14411447
#[inline]
14421448
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError> {
1443-
variant
1444-
.try_as_sys_of_type(VariantType::Nil)
1445-
.map(|_| std::marker::PhantomData)
1449+
if variant.is_nil() {
1450+
return Ok(std::marker::PhantomData);
1451+
}
1452+
1453+
Err(FromVariantError::InvalidVariantType {
1454+
variant_type: variant.get_type(),
1455+
expected: VariantType::Nil,
1456+
})
14461457
}
14471458
}
14481459

0 commit comments

Comments
 (0)