Skip to content

Commit

Permalink
fix bug where Interface::inherits() impls were not checking against b…
Browse files Browse the repository at this point in the history
…ase classes

The check for whether to include a recursive call to
Interface::inherits() for an interface's base class was incorrectly
always returning false, since it was checking the "bases" iteration
variable from a previous section of the method. Change it to correctly
check against the original "record.bases", and tighten up the scope for
the base class traversal loops since that would have prevented this
mistake from occurring.
  • Loading branch information
glowcoil committed Jun 9, 2023
1 parent a32ccdb commit 64fc2fe
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions com-scrape/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,16 @@ impl<'a, W: Write> RustPrinter<'a, W> {
self.sink,
"{indent}unsafe impl ::com_scrape_types::Inherits<{name}> for {name} {{}}"
)?;
let mut bases = &record.bases;
while let Some(base) = bases.first() {
let base_name = &base.name;
writeln!(
self.sink,
"{indent}unsafe impl ::com_scrape_types::Inherits<{base_name}> for {name} {{}}"
)?;
bases = &base.bases;
{
let mut bases = &record.bases;
while let Some(base) = bases.first() {
let base_name = &base.name;
writeln!(
self.sink,
"{indent}unsafe impl ::com_scrape_types::Inherits<{base_name}> for {name} {{}}"
)?;
bases = &base.bases;
}
}

let iid_generator = self.options.iid_generator.as_ref().ok_or_else(|| {
Expand Down Expand Up @@ -249,7 +251,7 @@ impl<'a, W: Write> RustPrinter<'a, W> {
writeln!(self.sink, "{indent} #[inline]")?;
writeln!(self.sink, "{indent} fn inherits(iid: &Guid) -> bool {{")?;
write!(self.sink, "{indent} iid == &Self::IID")?;
if let Some(base) = bases.first() {
if let Some(base) = record.bases.first() {
let base_name = &base.name;
write!(self.sink, " || {base_name}::inherits(iid)")?;
}
Expand Down Expand Up @@ -293,14 +295,16 @@ impl<'a, W: Write> RustPrinter<'a, W> {

if !self.options.skip_interface_traits.contains(&record.name) {
write!(self.sink, "{indent}pub trait {name}Trait")?;
let mut bases = &record.bases;
while let Some(base) = bases.first() {
if !self.options.skip_interface_traits.contains(&base.name) {
let base_name = &base.name;
write!(self.sink, ": {base_name}Trait")?;
break;
{
let mut bases = &record.bases;
while let Some(base) = bases.first() {
if !self.options.skip_interface_traits.contains(&base.name) {
let base_name = &base.name;
write!(self.sink, ": {base_name}Trait")?;
break;
}
bases = &base.bases;
}
bases = &base.bases;
}
writeln!(self.sink, " {{")?;

Expand Down Expand Up @@ -332,16 +336,18 @@ impl<'a, W: Write> RustPrinter<'a, W> {
self.sink,
"{indent} P::Target: ::com_scrape_types::Inherits<{name}>,"
)?;
let mut bases = &record.bases;
while let Some(base) = bases.first() {
if !self.options.skip_interface_traits.contains(&base.name) {
let base_name = &base.name;
writeln!(
self.sink,
"{indent} P::Target: ::com_scrape_types::Inherits<{base_name}>,"
)?;
{
let mut bases = &record.bases;
while let Some(base) = bases.first() {
if !self.options.skip_interface_traits.contains(&base.name) {
let base_name = &base.name;
writeln!(
self.sink,
"{indent} P::Target: ::com_scrape_types::Inherits<{base_name}>,"
)?;
}
bases = &base.bases;
}
bases = &base.bases;
}
writeln!(self.sink, "{indent}{{")?;

Expand Down Expand Up @@ -391,7 +397,6 @@ impl<'a, W: Write> RustPrinter<'a, W> {
self.sink,
"{indent} C: {name}Trait + Class + Implements<I>,"
)?;
// writeln!(self.sink, "{indent} I: Inherits<{name}>,")?;
writeln!(self.sink, "{indent} {{")?;

#[rustfmt::skip]
Expand Down

0 comments on commit 64fc2fe

Please sign in to comment.