Type Approximation: add separate flag to control approx. anonymous type

This extra flexibility is useful for IDE where we always want to
approximate anonymous types but may not want to approximate other local
 types
This commit is contained in:
Tianyu Geng
2021-12-07 10:31:29 -08:00
committed by teamcity
parent c5c606924c
commit a5844b754e
7 changed files with 28 additions and 2 deletions
@@ -169,9 +169,9 @@ abstract class AbstractTypeApproximator(
private fun approximateLocalTypes(type: SimpleTypeMarker, conf: TypeApproximatorConfiguration, toSuper: Boolean): SimpleTypeMarker? {
if (!toSuper) return null
if (!conf.localTypes) return null
if (!conf.localTypes && !conf.anonymous) return null
val constructor = type.typeConstructor()
val needApproximate = conf.localTypes && constructor.isLocalType()
val needApproximate = (conf.localTypes && constructor.isLocalType()) || (conf.anonymous && constructor.isAnonymous())
if (!needApproximate) return null
val superConstructor = constructor.supertypes().first().typeConstructor()
val typeCheckerContext = newTypeCheckerState(
@@ -25,6 +25,12 @@ open class TypeApproximatorConfiguration {
open val intersectionTypesInContravariantPositions = false
open val localTypes = false
/**
* Whether to approximate anonymous type. This flag does not have any effect if `localTypes` is true because all anonymous types are
* local.
*/
open val anonymous = false
open val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean = { false }
open fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean =
true // false means that this type we can leave as is