Skip to content

Fix: changed bitfields to be i64 instead of u64 #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions godot-codegen/src/generator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ fn make_enum_engine_trait_impl(enum_: &Enum) -> TokenStream {
// }

impl #engine_trait for #name {
fn try_from_ord(ord: u64) -> Option<Self> {
fn try_from_ord(ord: i64) -> Option<Self> {
Some(Self { ord })
}

fn ord(self) -> u64 {
fn ord(self) -> i64 {
self.ord
}
}
Expand Down
6 changes: 3 additions & 3 deletions godot-codegen/src/models/domain/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Enum {
/// The type we use to represent values of this enum.
pub fn ord_type(&self) -> Ident {
if self.is_bitfield {
ident("u64")
ident("i64")
} else {
ident("i32")
}
Expand Down Expand Up @@ -126,7 +126,7 @@ pub struct Enumerator {
#[derive(Clone)]
pub enum EnumeratorValue {
Enum(i32),
Bitfield(u64),
Bitfield(i64),
}

impl EnumeratorValue {
Expand All @@ -145,7 +145,7 @@ impl EnumeratorValue {
// Conversion is safe because i64 is used in the original JSON.
match self {
EnumeratorValue::Enum(i) => *i as i64,
EnumeratorValue::Bitfield(i) => *i as i64,
EnumeratorValue::Bitfield(i) => *i,
}
}

Expand Down
9 changes: 1 addition & 8 deletions godot-codegen/src/models/domain_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,7 @@ impl Enum {
impl Enumerator {
pub fn from_json(json: &JsonEnumConstant, rust_name: Ident, is_bitfield: bool) -> Self {
let value = if is_bitfield {
let ord = json.value.try_into().unwrap_or_else(|_| {
panic!(
"bitfield value {} = {} is negative; please report this",
json.name, json.value
)
});

EnumeratorValue::Bitfield(ord)
EnumeratorValue::Bitfield(json.value)
} else {
let ord = json.value.try_into().unwrap_or_else(|_| {
panic!(
Expand Down
6 changes: 3 additions & 3 deletions godot-core/src/obj/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ pub trait EngineEnum: Copy {

/// Auto-implemented for all engine-provided bitfields.
pub trait EngineBitfield: Copy {
fn try_from_ord(ord: u64) -> Option<Self>;
fn try_from_ord(ord: i64) -> Option<Self>;

/// Ordinal value of the bit flag, as specified in Godot.
fn ord(self) -> u64;
fn ord(self) -> i64;

fn from_ord(ord: u64) -> Self {
fn from_ord(ord: i64) -> Self {
Self::try_from_ord(ord)
.unwrap_or_else(|| panic!("ordinal {ord} does not map to any valid bit flag"))
}
Expand Down
6 changes: 3 additions & 3 deletions itest/rust/src/object_tests/property_template_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ fn property_template_test(ctx: &TestContext) {
let mut rust_usage = rust_prop.get("usage").unwrap().to::<i64>();

// the GDSscript variables are script variables, and so have `PROPERTY_USAGE_SCRIPT_VARIABLE` set.
if rust_usage == PropertyUsageFlags::STORAGE.ord() as i64 {
if rust_usage == PropertyUsageFlags::STORAGE.ord() {
// `PROPERTY_USAGE_SCRIPT_VARIABLE` does the same thing as `PROPERTY_USAGE_STORAGE` and so
// GDScript doesn't set both if it doesn't need to.
rust_usage = PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64
rust_usage = PropertyUsageFlags::SCRIPT_VARIABLE.ord()
} else {
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE.ord() as i64;
rust_usage |= PropertyUsageFlags::SCRIPT_VARIABLE.ord();
}

rust_prop.set("usage", rust_usage);
Expand Down
Loading