@@ -560,82 +560,71 @@ class _ClassVerifier {
560560 /// [CompileTimeErrorCode.recursiveInterfaceInheritanceImplements] ,
561561 /// [CompileTimeErrorCode.recursiveInterfaceInheritanceOn] ,
562562 /// [CompileTimeErrorCode.recursiveInterfaceInheritanceWith] .
563- bool _checkForRecursiveInterfaceInheritance (
564- InterfaceElementImpl element, [
565- List <InterfaceElement >? path,
566- ]) {
567- path ?? = < InterfaceElement > [];
568-
569- // Detect error condition.
570- int size = path.length;
571- // If this is not the base case (size > 0), and the enclosing class is the
572- // given class element then report an error.
573- if (size > 0 && classElement == element) {
574- String className = classElement.displayName;
575- if (size > 1 ) {
576- // Construct a string showing the cyclic implements path:
577- // "A, B, C, D, A"
578- String separator = ", " ;
579- StringBuffer buffer = StringBuffer ();
580- for (int i = 0 ; i < size; i++ ) {
581- buffer.write (path[i].displayName);
582- buffer.write (separator);
583- }
584- buffer.write (element.displayName);
585- reporter.atElement2 (
586- classElement,
587- CompileTimeErrorCode .recursiveInterfaceInheritance,
588- arguments: [className, buffer.toString ()],
589- );
590- return true ;
591- } else {
592- // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or
593- // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or
594- // RECURSIVE_INTERFACE_INHERITANCE_ON or
595- // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH
563+ bool _checkForRecursiveInterfaceInheritance (InterfaceElementImpl element) {
564+ var cycle = element.interfaceCycle;
565+ if (cycle == null ) {
566+ return false ;
567+ }
568+
569+ if (superclass case var superclass? ) {
570+ if (superclass.element == element) {
596571 reporter.atElement2 (
597- classElement ,
598- _getRecursiveErrorCode (element) ,
599- arguments: [className ],
572+ element ,
573+ CompileTimeErrorCode .recursiveInterfaceInheritanceExtends ,
574+ arguments: [element.displayName ],
600575 );
601576 return true ;
602577 }
603578 }
604579
605- if (path.indexOf (element) > 0 ) {
606- return false ;
607- }
608- path.add (element);
609-
610- // n-case
611- var supertype = element.supertype;
612- if (supertype != null &&
613- _checkForRecursiveInterfaceInheritance (supertype.element, path)) {
614- return true ;
615- }
616-
617- for (var type in element.mixins) {
618- if (_checkForRecursiveInterfaceInheritance (type.element, path)) {
619- return true ;
580+ if (onClause case var onClause? ) {
581+ for (var typeAnnotation in onClause.superclassConstraints) {
582+ if (typeAnnotation.element == element) {
583+ reporter.atElement2 (
584+ element,
585+ CompileTimeErrorCode .recursiveInterfaceInheritanceOn,
586+ arguments: [element.displayName],
587+ );
588+ return true ;
589+ }
620590 }
621591 }
622592
623- if (element is MixinElementImpl ) {
624- for (var type in element.superclassConstraints) {
625- if (_checkForRecursiveInterfaceInheritance (type.element, path)) {
593+ if (withClause case var withClause? ) {
594+ for (var typeAnnotation in withClause.mixinTypes) {
595+ if (typeAnnotation.element == element) {
596+ reporter.atElement2 (
597+ element,
598+ CompileTimeErrorCode .recursiveInterfaceInheritanceWith,
599+ arguments: [element.displayName],
600+ );
626601 return true ;
627602 }
628603 }
629604 }
630605
631- for (var type in element.interfaces) {
632- if (_checkForRecursiveInterfaceInheritance (type.element, path)) {
633- return true ;
606+ if (implementsClause case var implementsClause? ) {
607+ for (var typeAnnotation in implementsClause.interfaces) {
608+ if (typeAnnotation.element == element) {
609+ reporter.atElement2 (
610+ element,
611+ CompileTimeErrorCode .recursiveInterfaceInheritanceImplements,
612+ arguments: [element.displayName],
613+ );
614+ return true ;
615+ }
634616 }
635617 }
636618
637- path.removeAt (path.length - 1 );
638- return false ;
619+ reporter.atElement2 (
620+ classElement,
621+ CompileTimeErrorCode .recursiveInterfaceInheritance,
622+ arguments: [
623+ element.displayName,
624+ cycle.map ((e) => e.displayName).join (', ' ),
625+ ],
626+ );
627+ return true ;
639628 }
640629
641630 void _checkIllegalConcreteEnumMemberDeclaration (Token name) {
@@ -742,30 +731,6 @@ class _ClassVerifier {
742731 return true ;
743732 }
744733
745- /// Return the error code that should be used when the given class [element]
746- /// references itself directly.
747- DiagnosticCode _getRecursiveErrorCode (InterfaceElement element) {
748- if (element.supertype? .element == classElement) {
749- return CompileTimeErrorCode .recursiveInterfaceInheritanceExtends;
750- }
751-
752- if (element is MixinElement ) {
753- for (var type in element.superclassConstraints) {
754- if (type.element == classElement) {
755- return CompileTimeErrorCode .recursiveInterfaceInheritanceOn;
756- }
757- }
758- }
759-
760- for (var type in element.mixins) {
761- if (type.element == classElement) {
762- return CompileTimeErrorCode .recursiveInterfaceInheritanceWith;
763- }
764- }
765-
766- return CompileTimeErrorCode .recursiveInterfaceInheritanceImplements;
767- }
768-
769734 /// If [name] is not implemented in the extended concrete class, the
770735 /// issue should be fixed there, and then [classElement] will not have it too.
771736 bool _isNotImplementedInConcreteSuperClass (Name name) {
0 commit comments