Commit f65f719
[element model] fix unsafe
See: b/374689139.
https://dart-review.googlesource.com/c/sdk/+/390941 is blocking an SDK roll.
Root cause:
```
Action threw an exception: type 'ConstructorMember' is not a subtype of type 'ConstructorFragment' in type cast
#0 InterfaceTypeImpl.constructors2.<anonymous closure> (package:analyzer/src/dart/element/type.dart:569)
#1 MappedListIterable.elementAt (dart:_internal/iterable.dart:435)
#2 ListIterator.moveNext (dart:_internal/iterable.dart:364)
#3 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189)
#4 new _GrowableList.of (dart:core-patch/growable_array.dart:150)
#5 new List.of (dart:core-patch/array_patch.dart:39)
#6 ListIterable.toList (dart:_internal/iterable.dart:224)
#7 InterfaceTypeImpl.constructors2 (package:analyzer/src/dart/element/type.dart:570)
#8 _Visitor._hasConstConstructorInvocation (package:linter/src/rules/prefer_const_constructors_in_immutables.dart:110)
#9 _Visitor.visitConstructorDeclaration (package:linter/src/rules/prefer_const_constructors_in_immutables.dart:58)
```
To verify the fix locally:
```
solo_test_X() async {
await assertNoErrorsInCode(r'''
class A<T> {}
''');
var A = findElement.class_('A').instantiate(
typeArguments: [intType],
nullabilitySuffix: NullabilitySuffix.none,
);
A.constructors2;
}
```
Bug: b/374689139
Change-Id: I70034d938d840dc0c3939db27e7116164e4617e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391483
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>ConstructorMember cast1 parent 98ddead commit f65f719
File tree
2 files changed
+22
-1
lines changed- pkg
- analyzer/lib/src/dart/element
- linter/test/rules
2 files changed
+22
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | | - | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
558 | 564 | | |
559 | 565 | | |
560 | 566 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
408 | 423 | | |
409 | 424 | | |
410 | 425 | | |
| |||
0 commit comments