Skip to content

Commit

Permalink
add to unbounded type parameters
Browse files Browse the repository at this point in the history
(cherry picked from commit 8bd44ea)
  • Loading branch information
neetopia authored and KSP Auto Pick committed Jan 26, 2023
1 parent 354e861 commit d6661bd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package com.google.devtools.ksp.symbol.impl.kotlin
import com.google.devtools.ksp.KSObjectCache
import com.google.devtools.ksp.memoized
import com.google.devtools.ksp.processing.impl.KSNameImpl
import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.KSExpectActual
import com.google.devtools.ksp.symbol.KSName
import com.google.devtools.ksp.symbol.KSTypeParameter
import com.google.devtools.ksp.symbol.KSTypeReference
import com.google.devtools.ksp.symbol.KSVisitor
import com.google.devtools.ksp.symbol.Variance
import com.google.devtools.ksp.symbol.impl.synthetic.KSTypeReferenceSyntheticImpl
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtTypeParameter
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
Expand Down Expand Up @@ -68,7 +70,11 @@ class KSTypeParameterImpl private constructor(val ktTypeParameter: KtTypeParamet
it.subjectTypeParameterName!!.getReferencedName() == ktTypeParameter.nameAsSafeName.asString()
}
.map { it.boundTypeReference }
).filterNotNull().map { KSTypeReferenceImpl.getCached(it) }.memoized()
).filterNotNull().map { KSTypeReferenceImpl.getCached(it) }.ifEmpty {
sequenceOf(
KSTypeReferenceSyntheticImpl.getCached(ResolverImpl.instance!!.builtIns.anyType.makeNullable(), this)
)
}.memoized()
}

override val qualifiedName: KSName? by lazy {
Expand Down
3 changes: 3 additions & 0 deletions test-utils/testData/api/equivalentJavaWildcards.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
// Y : X -> X
// <init> : Y -> Y
// A : Any -> Any
// T1 : Any? -> Any?
// T2 : Any? -> Any?
// <init> : A<T1, T2> -> A<T1, T2>
// B : Any -> Any
// T : Any? -> Any?
// synthetic constructor for B : B<*> -> B<out Any?>
// bar1 : [@kotlin.jvm.JvmSuppressWildcards] A<X, X> -> [@kotlin.jvm.JvmSuppressWildcards] A<X, X>
// - INVARIANT X : X -> X
Expand Down
1 change: 1 addition & 0 deletions test-utils/testData/api/javaWildcards2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MyEnum : Any
// <init> : MyEnum
// VarianceSubjectSuppressed : Any
// R : Any?
// starList : List<Any?>
// typeArgList : List<R>
// numberList : List<Number>
Expand Down
1 change: 1 addition & 0 deletions test-utils/testData/api/libOrigins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
// reference: Any: KOTLIN_LIB
// reference: Any: KOTLIN_LIB
// reference: Any: SYNTHETIC
// reference: Any?: SYNTHETIC
// reference: ArrayList<(T2..T2?)>: JAVA_LIB
// reference: Byte: JAVA_LIB
// reference: Byte: JAVA_LIB
Expand Down
3 changes: 3 additions & 0 deletions test-utils/testData/api/parent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// parent of INVARIANT T: Map
// parent of Map: Map
// parent of Map: Alias
// parent of Any?: T
// parent of T: Alias
// parent of Alias: File: a.kt
// parent of Int: Int
Expand All @@ -49,6 +50,7 @@
// parent of topProp: File: a.kt
// parent of T: T
// parent of T: topFun
// parent of Any?: T
// parent of T: topFun
// parent of Anno: Anno
// parent of Anno: @Anno
Expand All @@ -68,6 +70,7 @@
// parent of Int: memberFun
// parent of memberFun: topClass
// parent of Any: InnerClass
// parent of Any?: P
// parent of P: InnerClass
// parent of InnerClass: topClass
// parent of P: P
Expand Down
13 changes: 13 additions & 0 deletions test-utils/testData/api/varianceTypeCheck.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,49 @@
// TEST PROCESSOR: TypeComparisonProcessor
// EXPECTED:
// Any ?= Any : true
// Any ?= Any? : false
// Any ?= Foo<*> : true
// Any ?= Foo<A> : true
// Any ?= Foo<C> : true
// Any ?= Foo<in B> : true
// Any ?= Foo<out B> : true
// Any? ?= Any : true
// Any? ?= Any? : true
// Any? ?= Foo<*> : true
// Any? ?= Foo<A> : true
// Any? ?= Foo<C> : true
// Any? ?= Foo<in B> : true
// Any? ?= Foo<out B> : true
// Foo<*> ?= Any : false
// Foo<*> ?= Any? : false
// Foo<*> ?= Foo<*> : true
// Foo<*> ?= Foo<A> : true
// Foo<*> ?= Foo<C> : true
// Foo<*> ?= Foo<in B> : true
// Foo<*> ?= Foo<out B> : true
// Foo<A> ?= Any : false
// Foo<A> ?= Any? : false
// Foo<A> ?= Foo<*> : false
// Foo<A> ?= Foo<A> : true
// Foo<A> ?= Foo<C> : false
// Foo<A> ?= Foo<in B> : false
// Foo<A> ?= Foo<out B> : false
// Foo<C> ?= Any : false
// Foo<C> ?= Any? : false
// Foo<C> ?= Foo<*> : false
// Foo<C> ?= Foo<A> : false
// Foo<C> ?= Foo<C> : true
// Foo<C> ?= Foo<in B> : false
// Foo<C> ?= Foo<out B> : false
// Foo<in B> ?= Any : false
// Foo<in B> ?= Any? : false
// Foo<in B> ?= Foo<*> : false
// Foo<in B> ?= Foo<A> : true
// Foo<in B> ?= Foo<C> : false
// Foo<in B> ?= Foo<in B> : true
// Foo<in B> ?= Foo<out B> : false
// Foo<out B> ?= Any : false
// Foo<out B> ?= Any? : false
// Foo<out B> ?= Foo<*> : false
// Foo<out B> ?= Foo<A> : false
// Foo<out B> ?= Foo<C> : true
Expand Down

0 comments on commit d6661bd

Please sign in to comment.