Skip to content

Commit e4dfda3

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Extension type. Issue 53725. Use representationTypeErasure of the matched type.
Bug: #53725 Change-Id: Ia9ea1b964288f05a19b23562a5c1e08e8dff5aa0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330981 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent b7591ed commit e4dfda3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pkg/analyzer/lib/src/dart/element/type_system.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ class TypeSystemImpl implements TypeSystem {
140140
/// type that implements both [left] and [right], regardless of whether
141141
/// [left] is a subtype of [right], or [right] is a subtype of [left].
142142
bool canBeSubtypeOf(DartType left, DartType right) {
143+
if (left case InterfaceTypeImpl(:final representationTypeErasure?)) {
144+
left = representationTypeErasure;
145+
}
146+
143147
// If one is `Null`, then the other must be nullable.
144148
final leftIsNullable = isPotentiallyNullable(left);
145149
final rightIsNullable = isPotentiallyNullable(right);

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ void f(double x) {
107107
''');
108108
}
109109

110+
test_interfaceType2_matchedExtensionType_requiredRepresentation() async {
111+
await assertNoErrorsInCode('''
112+
void f(A x) {
113+
if (x case int _) {}
114+
}
115+
116+
extension type A(int _) {}
117+
''');
118+
}
119+
120+
test_interfaceType2_matchedExtensionTypeUnrelated_requiredFinal() async {
121+
await assertErrorsInCode('''
122+
void f(A x) {
123+
if (x case C _) {}
124+
}
125+
126+
extension type A(B _) {}
127+
128+
class B {}
129+
130+
final class C {}
131+
''', [
132+
error(WarningCode.PATTERN_NEVER_MATCHES_VALUE_TYPE, 27, 1),
133+
]);
134+
}
135+
110136
test_interfaceType2_matchedFinal_enumSubtype() async {
111137
await assertNoErrorsInCode('''
112138
void f(A x) {

0 commit comments

Comments
 (0)