Skip to content

fix(stackable-versioned): Emit right type for unchanged fields #860

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

Merged
merged 3 commits into from
Sep 9, 2024
Merged
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
78 changes: 57 additions & 21 deletions crates/stackable-versioned-macros/src/codegen/common/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,36 +297,69 @@ where
ItemStatus::Addition { .. } => {
chain.insert(version.inner, ItemStatus::NotPresent)
}
ItemStatus::Change { from_ident, .. } => {
chain.insert(version.inner, ItemStatus::NoChange(from_ident.clone()))
}
ItemStatus::Deprecation { previous_ident, .. } => chain
.insert(version.inner, ItemStatus::NoChange(previous_ident.clone())),
ItemStatus::NoChange(ident) => {
chain.insert(version.inner, ItemStatus::NoChange(ident.clone()))
}
ItemStatus::Change {
from_ident,
from_type,
..
} => chain.insert(
version.inner,
ItemStatus::NoChange {
ident: from_ident.clone(),
ty: from_type.clone(),
},
),
ItemStatus::Deprecation { previous_ident, .. } => chain.insert(
version.inner,
ItemStatus::NoChange {
ident: previous_ident.clone(),
ty: self.inner.ty(),
},
),
ItemStatus::NoChange { ident, ty } => chain.insert(
version.inner,
ItemStatus::NoChange {
ident: ident.clone(),
ty: ty.clone(),
},
),
ItemStatus::NotPresent => unreachable!(),
},
(Some(status), None) => {
let ident = match status {
ItemStatus::Addition { ident, .. } => ident,
ItemStatus::Change { to_ident, .. } => to_ident,
ItemStatus::Deprecation { ident, .. } => ident,
ItemStatus::NoChange(ident) => ident,
let (ident, ty) = match status {
ItemStatus::Addition { ident, ty, .. } => (ident, ty),
ItemStatus::Change {
to_ident, to_type, ..
} => (to_ident, to_type),
ItemStatus::Deprecation { ident, .. } => (ident, &self.inner.ty()),
ItemStatus::NoChange { ident, ty } => (ident, ty),
ItemStatus::NotPresent => unreachable!(),
};

chain.insert(version.inner, ItemStatus::NoChange(ident.clone()))
chain.insert(
version.inner,
ItemStatus::NoChange {
ident: ident.clone(),
ty: ty.clone(),
},
)
}
(Some(status), Some(_)) => {
let ident = match status {
ItemStatus::Addition { ident, .. } => ident,
ItemStatus::Change { to_ident, .. } => to_ident,
ItemStatus::NoChange(ident) => ident,
let (ident, ty) = match status {
ItemStatus::Addition { ident, ty, .. } => (ident, ty),
ItemStatus::Change {
to_ident, to_type, ..
} => (to_ident, to_type),
ItemStatus::NoChange { ident, ty, .. } => (ident, ty),
_ => unreachable!(),
};

chain.insert(version.inner, ItemStatus::NoChange(ident.clone()))
chain.insert(
version.inner,
ItemStatus::NoChange {
ident: ident.clone(),
ty: ty.clone(),
},
)
}
_ => unreachable!(),
};
Expand Down Expand Up @@ -365,7 +398,10 @@ pub(crate) enum ItemStatus {
note: Option<String>,
ident: Ident,
},
NoChange(Ident),
NoChange {
ident: Ident,
ty: Type,
},
NotPresent,
}

Expand All @@ -375,7 +411,7 @@ impl ItemStatus {
ItemStatus::Addition { ident, .. } => Some(ident),
ItemStatus::Change { to_ident, .. } => Some(to_ident),
ItemStatus::Deprecation { ident, .. } => Some(ident),
ItemStatus::NoChange(ident) => Some(ident),
ItemStatus::NoChange { ident, .. } => Some(ident),
ItemStatus::NotPresent => None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl VersionedVariant {
#ident,
})
}
ItemStatus::NoChange(ident) => Some(quote! {
ItemStatus::NoChange { ident, .. } => Some(quote! {
#(#original_attributes)*
#ident,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ impl VersionedField {
})
}
ItemStatus::NotPresent => None,
ItemStatus::NoChange(field_ident) => Some(quote! {
ItemStatus::NoChange { ident, ty } => Some(quote! {
#(#original_attributes)*
pub #field_ident: #field_type,
pub #ident: #ty,
}),
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/stackable-versioned-macros/tests/good/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use stackable_versioned_macros::versioned;
)]
pub(crate) struct Foo {
#[versioned(
added(since = "v1alpha1"),
changed(since = "v1beta1", from_name = "jjj", from_type = "u8"),
changed(since = "v1", from_type = "u16"),
deprecated(since = "v2", note = "not empty")
Expand Down
2 changes: 2 additions & 0 deletions crates/stackable-versioned/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ All notable changes to this project will be documented in this file.

- Report variant rename validation error at the correct span and trim underscores
from variants not using PascalCase ([#842]).
- Emit correct struct field types for fields with no changes (NoChange) ([#860]).

[#842]: https://github.com/stackabletech/operator-rs/pull/842
[#844]: https://github.com/stackabletech/operator-rs/pull/844
[#847]: https://github.com/stackabletech/operator-rs/pull/847
[#850]: https://github.com/stackabletech/operator-rs/pull/850
[#859]: https://github.com/stackabletech/operator-rs/pull/859
[#860]: https://github.com/stackabletech/operator-rs/pull/860

## [0.1.1] - 2024-07-10

Expand Down