Skip to content

Commit b6a9a40

Browse files
scheglovCommit Queue
authored andcommitted
Isse 61829. Fix for RangeError in _checkForMixinSuperclassConstraints()
The trick is to have both unresolved mixin, and interface cycle. Bug: #61829 Change-Id: Ie82eb8d3ddbd1dc3a0fe551792eb2387d7689655 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457802 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 8970b71 commit b6a9a40

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,16 +4315,22 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
43154315
int mixinIndex,
43164316
NamedTypeImpl mixinName,
43174317
) {
4318+
var enclosingClass = _enclosingClass!;
43184319
var mixinType = mixinName.type as InterfaceTypeImpl;
43194320
for (var constraint in mixinType.superclassConstraints) {
4320-
var superType = _enclosingClass!.supertype as InterfaceTypeImpl;
4321+
var superType = enclosingClass.supertype as InterfaceTypeImpl;
43214322
superType = superType.withNullability(NullabilitySuffix.none);
43224323

43234324
bool isSatisfied = typeSystem.isSubtypeOf(superType, constraint);
43244325
if (!isSatisfied) {
43254326
for (int i = 0; i < mixinIndex && !isSatisfied; i++) {
4327+
// If there are less mixin types than mixin nodes, escape.
4328+
if (i >= enclosingClass.mixins.length) {
4329+
return false;
4330+
}
4331+
// Probe a previous mixin type.
43264332
isSatisfied = typeSystem.isSubtypeOf(
4327-
_enclosingClass!.mixins[i],
4333+
enclosingClass.mixins[i],
43284334
constraint,
43294335
);
43304336
}

pkg/analyzer/test/src/diagnostics/mixin_application_not_implemented_interface_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ main() {
1616
@reflectiveTest
1717
class MixinApplicationNotImplementedInterfaceTest
1818
extends PubPackageResolutionTest {
19+
test_class_hasRecursion() async {
20+
// https://github.com/dart-lang/sdk/issues/61829
21+
await assertErrorsInCode(
22+
'''
23+
class A {}
24+
abstract class X with Unresolved, M, CycleWithX {}
25+
mixin M on A {}
26+
mixin CycleWithX on X {}
27+
''',
28+
[
29+
error(CompileTimeErrorCode.recursiveInterfaceInheritance, 26, 1),
30+
error(CompileTimeErrorCode.mixinOfNonClass, 33, 10),
31+
error(CompileTimeErrorCode.recursiveInterfaceInheritance, 84, 10),
32+
],
33+
);
34+
}
35+
1936
test_class_matchingInterface() async {
2037
await assertNoErrorsInCode('''
2138
abstract class A<T> {}

0 commit comments

Comments
 (0)