@@ -112,7 +112,7 @@ class TypeResolver(private val typeRegistry: TypeRegistry, private val hierarchy
112112 if (numDimensions == 0 ) baseType else baseType.makeArrayType(numDimensions)
113113 }
114114
115- return TypeStorage (type, concretePossibleTypes).filterInappropriateClassesForCodeGeneration ()
115+ return TypeStorage (type, concretePossibleTypes).removeInappropriateTypes ()
116116 }
117117
118118 private fun isInappropriateOrArrayOfMocksOrLocals (numDimensions : Int , baseType : Type ? ): Boolean {
@@ -182,46 +182,40 @@ class TypeResolver(private val typeRegistry: TypeRegistry, private val hierarchy
182182 else -> error(" Unexpected type $type " )
183183 }
184184
185- return TypeStorage (type, possibleTypes).filterInappropriateClassesForCodeGeneration ()
185+ return TypeStorage (type, possibleTypes).removeInappropriateTypes ()
186186 }
187187
188188 /* *
189- * Where possible, remove types that are not currently supported by code generation.
190- * For example, we filter out artificial entities (lambdas are an example of them)
191- * if the least common type is **not** artificial itself.
189+ * Remove wrapper types and, if any other type is available, artificial entities.
192190 */
193- private fun TypeStorage.filterInappropriateClassesForCodeGeneration (): TypeStorage {
194- val unwantedTypes = mutableSetOf<Type >()
195- val concreteTypes = mutableSetOf<Type >()
196-
191+ private fun TypeStorage.removeInappropriateTypes (): TypeStorage {
197192 val leastCommonSootClass = (leastCommonType as ? RefType )?.sootClass
198193 val keepArtificialEntities = leastCommonSootClass?.isArtificialEntity == true
199194
200- possibleConcreteTypes.forEach {
201- val sootClass = (it.baseType as ? RefType )?.sootClass ? : run {
202- // All not RefType should be included in the concreteTypes, e.g., arrays
203- concreteTypes + = it
204- return @forEach
195+ val appropriateTypes = possibleConcreteTypes.filter {
196+ // All not RefType should be included in the concreteTypes, e.g., arrays
197+ val sootClass = (it.baseType as ? RefType )?.sootClass ? : return @filter true
198+
199+ // All artificial entities except anonymous functions should be filtered out if we have another types
200+ if (sootClass.isArtificialEntity) {
201+ if (sootClass.isLambda) {
202+ return @filter true
203+ }
204+
205+ return @filter keepArtificialEntities
205206 }
206- when {
207- sootClass.isUtMock -> unwantedTypes + = it
208- sootClass.isArtificialEntity -> {
209- if (sootClass.isLambda) {
210- unwantedTypes + = it
211- } else if (keepArtificialEntities) {
212- concreteTypes + = it
213- }
207+
208+ // All wrappers should filtered out because they could not be instantiated
209+ workaround(WorkaroundReason .HACK ) {
210+ if (leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden) {
211+ return @filter false
214212 }
215- workaround(WorkaroundReason .HACK ) { leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden } -> Unit
216- else -> concreteTypes + = it
217213 }
218- }
219214
220- return if (concreteTypes.isEmpty()) {
221- copy(possibleConcreteTypes = unwantedTypes)
222- } else {
223- copy(possibleConcreteTypes = concreteTypes)
224- }
215+ return @filter true
216+ }.toSet()
217+
218+ return copy(possibleConcreteTypes = appropriateTypes)
225219 }
226220
227221 /* *
0 commit comments