Skip to content

Commit 996cfba

Browse files
authored
fix: unit enum variants other than Option::None being converted into ScriptValue::Unit (#360)
1 parent 4a4c039 commit 996cfba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

crates/bevy_mod_scripting_core/src/reflection_extensions.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ impl<T: PartialReflect + ?Sized> PartialReflectExt for T {
138138

139139
fn as_option(&self) -> Result<Option<&dyn PartialReflect>, InteropError> {
140140
if let bevy::reflect::ReflectRef::Enum(e) = self.reflect_ref() {
141-
if let Some(field) = e.field_at(0) {
142-
return Ok(Some(field));
143-
} else {
144-
return Ok(None);
141+
if e.is_type(Some("core"), "Option") {
142+
if let Some(field) = e.field_at(0) {
143+
return Ok(Some(field));
144+
} else {
145+
return Ok(None);
146+
}
145147
}
146148
}
147149

@@ -535,7 +537,13 @@ mod test {
535537

536538
#[test]
537539
fn test_as_option_none() {
540+
#[derive(Reflect)]
541+
enum Test {
542+
Unit,
543+
}
544+
538545
assert!(None::<i32>.as_option().unwrap().is_none());
546+
assert!(Test::Unit.as_option().is_err())
539547
}
540548

541549
#[test]

0 commit comments

Comments
 (0)