Skip to content

Commit

Permalink
fix: recursive export bug (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed Jul 15, 2022
1 parent b32fbc8 commit 4a57716
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/freezed/lib/src/tools/recursive_import_locator.dart
Expand Up @@ -30,17 +30,21 @@ class RecursiveImportLocator {
}
}

return libraries.any((lib) => _doesExportRecursively(
library: lib,
where: where,
whereLibrary: whereLibrary,
));
return libraries.any(
(lib) => _doesExportRecursively(
library: lib,
where: where,
whereLibrary: whereLibrary,
visited: {lib.library.librarySource.fullName},
),
);
}

bool _doesExportRecursively({
required _LibraryWithVisibility library,
required ExportPredicate where,
LibraryPredicate? whereLibrary,
required Set<String> visited,
}) {
if (library.isRelevant(whereLibrary)) {
if (library.exportedTopLevelElements.any(where)) {
Expand All @@ -49,11 +53,16 @@ class RecursiveImportLocator {
}

return library.exportedLibraries.any((export) {
return _doesExportRecursively(
library: export,
where: where,
whereLibrary: whereLibrary,
);
final name = export.library.librarySource.fullName;
if (!visited.contains(name)) {
return _doesExportRecursively(
library: export,
where: where,
whereLibrary: whereLibrary,
visited: visited..add(name),
);
}
return false;
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/freezed/test/integration/recursive.dart
@@ -0,0 +1,10 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'recursive2.dart';
export 'recursive2.dart';

part 'recursive.freezed.dart';

@freezed
class A with _$A {
factory A({B? parent}) = _A;
}
10 changes: 10 additions & 0 deletions packages/freezed/test/integration/recursive2.dart
@@ -0,0 +1,10 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'recursive.dart';
export 'recursive.dart';

part 'recursive2.freezed.dart';

@freezed
class B with _$B {
factory B({A? parent}) = _B;
}

0 comments on commit 4a57716

Please sign in to comment.