Skip to content

Detect and avoid cycles when resolving items. #2088

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 1 commit into from
Aug 24, 2021
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
8 changes: 8 additions & 0 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2723,8 +2723,16 @@ impl ItemResolver {
assert!(ctx.collected_typerefs());

let mut id = self.id;
let mut seen_ids = HashSet::default();
loop {
let item = ctx.resolve_item(id);

// Detect cycles and bail out. These can happen in certain cases
// involving incomplete qualified dependent types (#2085).
if !seen_ids.insert(id) {
return item;
}

let ty_kind = item.as_type().map(|t| t.kind());
match ty_kind {
Some(&TypeKind::ResolvedTypeRef(next_id))
Expand Down
17 changes: 17 additions & 0 deletions tests/expectations/tests/qualified-dependent-types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Foo {
pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Bar {
pub _address: u8,
}
16 changes: 16 additions & 0 deletions tests/headers/qualified-dependent-types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Issue #2085.

template<typename T>
struct Foo;

template<typename T, typename U>
struct Bar {};

template<typename T>
struct Bar<T, void> {
using BarDependent = typename Foo<T>::Dependent;
void method(const BarDependent &);
};

template<typename T>
void Bar<T, void>::method(const BarDependent &) {}