[_fe_analyzer_shared] Fix getField for WrappedStaticType
WrappedStaticType didn't forward 'getField' to its 'wrappedType',
thereby missing support for Object members on type variables.
Change-Id: I9b81d7e1f7c4fcc1620fd7d151af53b9046beda2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292362
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/exhaustive.dart b/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/exhaustive.dart
index 6d6ad2a..6f21d69 100644
--- a/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/exhaustive.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/exhaustive.dart
@@ -238,6 +238,10 @@
} else {
// This pattern doesn't test this field, so add a pattern for the
// field that matches all values. This way the columns stay aligned.
+ // TODO(johnniwinther): Enable this assert when extension members are
+ // handled.
+ //assert(type.getField(_fieldLookup, key) != null,
+ // "Type $type does not have a type for field $key");
result.add(new Space(path.add(key),
type.getField(_fieldLookup, key) ?? StaticType.nullableObject));
}
@@ -249,6 +253,10 @@
} else {
// This pattern doesn't test this field, so add a pattern for the
// field that matches all values. This way the columns stay aligned.
+ // TODO(johnniwinther): Enable this assert when extension members are
+ // handled.
+ // assert(type.getAdditionalField(key) != null,
+ // "Type $type does not have a type for additional field $key");
result.add(new Space(path.add(key),
type.getAdditionalField(key) ?? StaticType.nullableObject));
}
diff --git a/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/static_type.dart b/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/static_type.dart
index 3280423..c2a5862 100644
--- a/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/static_type.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/exhaustiveness/static_type.dart
@@ -113,8 +113,8 @@
Map<Key, StaticType> get fields => const {};
@override
- StaticType? getField(ObjectFieldLookup fieldLookup, Key name) {
- return fields[name];
+ StaticType? getField(ObjectFieldLookup fieldLookup, Key key) {
+ return fields[key];
}
@override
@@ -332,6 +332,11 @@
Map<Key, StaticType> get fields => wrappedType.fields;
@override
+ StaticType? getField(ObjectFieldLookup fieldLookup, Key key) {
+ return wrappedType.getField(fieldLookup, key);
+ }
+
+ @override
bool get isRecord => wrappedType.isRecord;
@override
diff --git a/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart b/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart
index 2f7b925..d5e2c42 100644
--- a/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart
@@ -749,6 +749,11 @@
Iterable<String> get supportedMarkers => markers.keys;
Future<void> runAll(List<String> args) async {
+ bool assertsEnabled = true;
+ try {
+ assert(false);
+ assertsEnabled = false;
+ } catch (_) {}
Set<MarkerTester> testers = markers.values.toSet();
int errorsCount = 0;
for (MarkerTester tester in testers) {
@@ -756,7 +761,12 @@
print('Running tester: ${tester.path} ${args.join(' ')}');
print('================================================================');
Process process = await Process.start(
- Platform.resolvedExecutable, [tester.uri.toString(), ...args],
+ Platform.resolvedExecutable,
+ [
+ if (assertsEnabled) '--enable_asserts',
+ tester.uri.toString(),
+ ...args
+ ],
mode: ProcessStartMode.inheritStdio);
if (await process.exitCode != 0) {
errorsCount++;
diff --git a/pkg/_fe_analyzer_shared/test/exhaustiveness/data/type_variable_members.dart b/pkg/_fe_analyzer_shared/test/exhaustiveness/data/type_variable_members.dart
index 6dbeabf..cbeb50b 100644
--- a/pkg/_fe_analyzer_shared/test/exhaustiveness/data/type_variable_members.dart
+++ b/pkg/_fe_analyzer_shared/test/exhaustiveness/data/type_variable_members.dart
@@ -12,13 +12,29 @@
*/
switch (o) {
Typedef(:var hashCode) /*space=Object?(hashCode: int)*/ => hashCode,
- Typedef(:var runtimeType) /*space=Object?(runtimeType: Type)*/ =>
+ Typedef(
+ :var runtimeType
+ ) /*
+ error=unreachable,
+ space=Object?(runtimeType: Type)
+ */
+ =>
runtimeType,
- Typedef(:var toString) /*space=Object?(toString: String Function())*/ =>
+ Typedef(
+ :var toString
+ ) /*
+ error=unreachable,
+ space=Object?(toString: String Function())
+ */
+ =>
toString(),
Typedef(
:var noSuchMethod
- ) /*space=Object?(noSuchMethod: dynamic Function(Invocation))*/ =>
+ ) /*
+ error=unreachable,
+ space=Object?(noSuchMethod: dynamic Function(Invocation))
+ */
+ =>
noSuchMethod,
_ /*space=()*/ => null,
};
@@ -27,8 +43,7 @@
exhaustiveHashCode(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(hashCode: Object()),
- fields={hashCode:-},
+ fields={hashCode:int},
subtypes={Object,Null},
type=Object?
*/
@@ -40,8 +55,7 @@
exhaustiveRuntimeType(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(runtimeType: Object()),
- fields={runtimeType:-},
+ fields={runtimeType:Type},
subtypes={Object,Null},
type=Object?
*/
@@ -54,8 +68,7 @@
exhaustiveToString(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(toString: Object()),
- fields={toString:-},
+ fields={toString:String Function()},
subtypes={Object,Null},
type=Object?
*/
@@ -70,8 +83,7 @@
exhaustiveNoSuchMethod(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(noSuchMethod: Object()),
- fields={noSuchMethod:-},
+ fields={noSuchMethod:dynamic Function(Invocation)},
subtypes={Object,Null},
type=Object?
*/
@@ -86,8 +98,8 @@
nonExhaustiveRestrictedValue(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(hashCode: Object()),
- fields={hashCode:-},
+ error=non-exhaustive:Object(hashCode: int()),
+ fields={hashCode:int},
subtypes={Object,Null},
type=Object?
*/
@@ -99,8 +111,8 @@
nonExhaustiveRestrictedType(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(noSuchMethod: Object()),
- fields={noSuchMethod:-},
+ error=non-exhaustive:Object(noSuchMethod: dynamic Function(Invocation) _),
+ fields={noSuchMethod:dynamic Function(Invocation)},
subtypes={Object,Null},
type=Object?
*/
@@ -115,20 +127,35 @@
unreachableMethod(Typedef o) {
return /*
checkingOrder={Object?,Object,Null},
- error=non-exhaustive:Object(hashCode: Object(), noSuchMethod: Object(), runtimeType: Object(), toString: Object()),
- fields={hashCode:-,noSuchMethod:-,runtimeType:-,toString:-},
+ fields={hashCode:int,noSuchMethod:dynamic Function(Invocation),runtimeType:Type,toString:String Function()},
subtypes={Object,Null},
type=Object?
*/
switch (o) {
Typedef(:var hashCode) /*space=Object?(hashCode: int)*/ => hashCode,
- Typedef(:var runtimeType) /*space=Object?(runtimeType: Type)*/ =>
+ Typedef(
+ :var runtimeType
+ ) /*
+ error=unreachable,
+ space=Object?(runtimeType: Type)
+ */
+ =>
runtimeType,
- Typedef(:var toString) /*space=Object?(toString: String Function())*/ =>
+ Typedef(
+ :var toString
+ ) /*
+ error=unreachable,
+ space=Object?(toString: String Function())
+ */
+ =>
toString(),
Typedef(
:var noSuchMethod
- ) /*space=Object?(noSuchMethod: dynamic Function(Invocation))*/ =>
+ ) /*
+ error=unreachable,
+ space=Object?(noSuchMethod: dynamic Function(Invocation))
+ */
+ =>
noSuchMethod,
};
}