@@ -28,21 +28,31 @@ class TsTypeSystem(
2828 override fun isSupertype (supertype : EtsType , type : EtsType ): Boolean {
2929 return when {
3030 type is AuxiliaryType -> {
31+ // Unknown and Any types are top types in the system
3132 if (supertype is EtsUnknownType || supertype is EtsAnyType ) {
3233 return true
3334 }
3435
36+ // We think that only ref types contain fields, and ObjectClass is a top type for ref types
3537 if (supertype == EtsHierarchy .OBJECT_CLASS ) {
3638 return true
3739 }
3840
41+ // If we compare two auxiliary types,
42+ // we should check if all fields of the first type are in the second type
3943 if (supertype is AuxiliaryType ) {
4044 return type.properties.all { it in supertype.properties }
4145 }
4246
43- val supertypeClass = project.projectAndSdkClasses.single { it.type.typeName == supertype.typeName }
47+ // TODO how to process unclearTypeRefs?
48+ val supertypeClass = project
49+ .projectAndSdkClasses
50+ .singleOrNull { it.type.typeName == supertype.typeName }
51+ ? : TODO (" For now we support only unique type resolution" )
4452 val supertypeFields = supertypeClass.getAllFields(hierarchy)
45- type.properties.all { it in supertypeFields.map { it.name } }
53+ val superTypeFieldNames = supertypeFields.mapTo(hashSetOf()) { it.name }
54+
55+ type.properties.all { it in superTypeFieldNames }
4656 }
4757
4858 supertype is AuxiliaryType -> {
@@ -54,8 +64,12 @@ class TsTypeSystem(
5464 return supertype.properties.isEmpty()
5565 }
5666
57- val clazz = project.projectAndSdkClasses.single { it.type.typeName == type.typeName }
67+ val clazz = project
68+ .projectAndSdkClasses
69+ .singleOrNull { it.type.typeName == type.typeName }
70+ ? : TODO (" For now we support only unique type resolution" )
5871 val typeFields = clazz.getAllFields(hierarchy)
72+
5973 typeFields.mapTo(mutableSetOf ()) { it.name }.containsAll(supertype.properties)
6074 }
6175
0 commit comments