Fix #33599 circular typedef stack overflow.
Fix #33599 stack overflow for recursive function type parameters
Bug: 33599
Change-Id: I31a14e9f941bfd6bb7c2dba09f671d887e535b2a
Reviewed-on: https://dart-review.googlesource.com/c/76040
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index 1657912..08a3048 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -3442,7 +3442,12 @@
"argumentTypes.length (${argumentTypes.length}) != parameterTypes.length (${parameterTypes.length})");
}
Element element = this.element;
- if (prune != null && prune.contains(element)) {
+ Element forCircularity = this.element;
+ if (element is GenericFunctionTypeElement &&
+ element.enclosingElement is FunctionTypeAliasElement) {
+ forCircularity = element.enclosingElement;
+ }
+ if (prune != null && prune.contains(forCircularity)) {
// Circularity found. Prune the type declaration.
return new CircularFunctionTypeImpl();
}
diff --git a/pkg/analyzer/test/generated/compile_time_error_code_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
index d4c18fe..679ca15 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code_test.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
@@ -6295,6 +6295,18 @@
verify([source]);
}
+ test_typedef_infiniteParameterBoundCycle() async {
+ Source source = addSource(r'''
+typedef F<X extends F> = F Function();
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [
+ CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF,
+ StrongModeCode.NOT_INSTANTIATED_BOUND,
+ ]);
+ verify([source]);
+ }
+
test_undefinedAnnotation_unresolved_identifier() async {
Source source = addSource(r'''
@unresolved
diff --git a/tests/co19_2/co19_2-analyzer.status b/tests/co19_2/co19_2-analyzer.status
index 80988a4..122453a 100644
--- a/tests/co19_2/co19_2-analyzer.status
+++ b/tests/co19_2/co19_2-analyzer.status
@@ -227,17 +227,9 @@
LanguageFeatures/Instantiate-to-bound/interface/interface_neg_assign_l2_t01: MissingCompileTimeError # Issue 33995
LanguageFeatures/Instantiate-to-bound/interface/interface_neg_assign_l2_t02: MissingCompileTimeError # Issue 33308
LanguageFeatures/Instantiate-to-bound/mixin/mixin_neg_l1_t02: MissingCompileTimeError # Issue 33596
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_named_extends_neg_l1_t02: Crash # Issue 33599
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_named_extends_neg_l2_t01: Crash # Issue 33599
LanguageFeatures/Instantiate-to-bound/typedef/typedef_named_extends_pos_l2_t01: CompileTimeError # Bad test
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_optparam_extends_neg_l1_t02: Crash # Issue 33599
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_optparam_extends_neg_l2_t01: Crash # Issue 33599
LanguageFeatures/Instantiate-to-bound/typedef/typedef_optparam_extends_pos_l2_t01: CompileTimeError # Bad test
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_param_extends_neg_l1_t02: Crash # Issue 33599
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_param_extends_neg_l2_t01: Crash # Issue 33599
LanguageFeatures/Instantiate-to-bound/typedef/typedef_param_extends_pos_l2_t01: CompileTimeError # Bad test
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_ret_extends_neg_l1_t02: Crash # Issue 33599
-LanguageFeatures/Instantiate-to-bound/typedef/typedef_ret_extends_neg_l2_t01: Crash # Issue 33599
LanguageFeatures/Instantiate-to-bound/typedef/typedef_ret_extends_pos_l2_t01: CompileTimeError # Bad test
LanguageFeatures/Super-bounded-types/static_analysis_A01_t02: CompileTimeError # Issue 32903
LanguageFeatures/Super-bounded-types/static_analysis_A01_t05: CompileTimeError # Issue 32903