@@ -263,6 +263,16 @@ private boolean isSubtypeHelper(JSType subtype, JSType supertype) {
263
263
private boolean isObjectSubtypeHelper (ObjectType subtype , ObjectType supertype ) {
264
264
TemplateTypeMap subtypeParams = subtype .getTemplateTypeMap ();
265
265
TemplateTypeMap supertypeParams = supertype .getTemplateTypeMap ();
266
+ boolean subAndSuperAreSameBaseType = false ;
267
+ if (subtype .isTemplatizedType () && supertype .isTemplatizedType ()) {
268
+ TemplatizedType templatizedSubType = subtype .toMaybeTemplatizedType ();
269
+ TemplatizedType templatizedSuperType = supertype .toMaybeTemplatizedType ();
270
+ ObjectType superTypeReferencedType = templatizedSuperType .getReferencedType ();
271
+ ObjectType subTypeReferencedType = templatizedSubType .getReferencedType ();
272
+ if (subTypeReferencedType .equals (superTypeReferencedType )) {
273
+ subAndSuperAreSameBaseType = true ;
274
+ }
275
+ }
266
276
boolean bivarantMatch = false ;
267
277
268
278
/*
@@ -284,7 +294,9 @@ private boolean isObjectSubtypeHelper(ObjectType subtype, ObjectType supertype)
284
294
bivarantMatch = true ;
285
295
}
286
296
287
- if (this .isUsingStructuralTyping && supertype .isStructuralType ()) {
297
+ if (!subAndSuperAreSameBaseType
298
+ && this .isUsingStructuralTyping
299
+ && supertype .isStructuralType ()) {
288
300
/*
289
301
* Do this before considering templatization in general.
290
302
*
@@ -293,7 +305,7 @@ private boolean isObjectSubtypeHelper(ObjectType subtype, ObjectType supertype)
293
305
*/
294
306
return this .isStructuralSubtypeHelper (
295
307
subtype , supertype , PropertyOptionality .VOIDABLE_PROPS_ARE_OPTIONAL );
296
- } else if (supertype .isRecordType ()) {
308
+ } else if (! subAndSuperAreSameBaseType && supertype .isRecordType ()) {
297
309
/*
298
310
* Anonymous record types are always considered structurally when supertypes.
299
311
*
0 commit comments