nnbd_migration: fix crash on mixin override

Migration tool currently crashes if a class overrides
some methods it got by adding a mixin.

Added a test for that and fixed the crash, the fix
boils down to casting to just `InterfaceElement` instead
of `ClassElement`.

Tested: added a new test
Change-Id: Iab5ddb26c4930ed2020d6f3caa0710e55f24d8c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275721
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
Ilya Yanok 2022-12-15 09:19:38 +00:00 committed by Commit Queue
parent 6cda72d39e
commit 822d15e7cc
2 changed files with 18 additions and 1 deletions

View file

@ -2773,7 +2773,8 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
ClassElement classElement,
Element overriddenElement) {
overriddenElement = overriddenElement.declaration!;
var overriddenClass = overriddenElement.enclosingElement as ClassElement;
var overriddenClass =
overriddenElement.enclosingElement as InterfaceElement;
var decoratedSupertype = _decoratedClassHierarchy!
.getDecoratedSupertype(classElement, overriddenClass);
var substitution = decoratedSupertype.asSubstitution;

View file

@ -5449,6 +5449,22 @@ class C {
expect(hasNullCheckHint(findNode.simple('int')), isFalse);
}
Future<void> test_override_mixin_method() async {
await analyze('''
mixin M {
int m(int/*1*/ x);
}
class C with M {
@override
int m(int/*2*/ x) => x;
}
''');
final int1 = decoratedTypeAnnotation('int/*1*/');
final int2 = decoratedTypeAnnotation('int/*2*/');
assertEdge(int1.node, int2.node, hard: false, checkable: false);
}
Future<void> test_override_parameter_function_typed() async {
await analyze('''
abstract class Base {