Rollback of "Eliminate some redundant subtype checking code from `RecordType`"
@@ -191,4 +191,37 @@ public class RecordType extends PrototypeObjectType {
public boolean isStructuralType() {
return true;
}
+
+ @Override
+ public boolean isSubtype(JSType that) {
+ return this.isSubtype(that, ImplCache.create(), SubtypingMode.NORMAL);
+ }
+
+ @Override
+ protected boolean isSubtype(JSType that,
+ ImplCache implicitImplCache, SubtypingMode subtypingMode) {
+ if (JSType.isSubtypeHelper(this, that, implicitImplCache, subtypingMode)) {
+ return true;
+ }
+
+ // Top of the record types is the empty record, or OBJECT_TYPE.
+ if (registry.getNativeObjectType(
+ JSTypeNative.OBJECT_TYPE).isSubtype(that, implicitImplCache, subtypingMode)) {
+ return true;
+ }
+
+ // A type is a subtype of a record type if it itself is a record
+ // type and it has at least the same members as the parent record type
+ // with the same types.
+ if (!that.isRecordType()) {
+ return false;
+ }
+
+ return ObjectType.isStructuralSubtypeHelper(
+ this,
+ that.toMaybeRecordType(),
+ implicitImplCache,
+ subtypingMode,
+ PropertyOptionality.ALL_PROPS_ARE_REQUIRED);
+ }
}
