FIR: resolve function type parameters
This commit is contained in:
+12
-2
@@ -6,14 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.descriptors
|
package org.jetbrains.kotlin.descriptors
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirRenderer
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.render
|
import org.jetbrains.kotlin.fir.render
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirTypeResolver
|
import org.jetbrains.kotlin.fir.resolve.FirTypeResolver
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.*
|
import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.transformSingle
|
import org.jetbrains.kotlin.fir.transformSingle
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeImpl
|
||||||
@@ -35,6 +33,7 @@ class FirTypeResolveTransformer(val superTypesOnly: Boolean = false) : FirTransf
|
|||||||
|
|
||||||
lateinit var scope: FirCompositeScope
|
lateinit var scope: FirCompositeScope
|
||||||
lateinit var packageFqName: FqName
|
lateinit var packageFqName: FqName
|
||||||
|
lateinit var file: FirFile
|
||||||
private var classLikeName: FqName = FqName.ROOT
|
private var classLikeName: FqName = FqName.ROOT
|
||||||
|
|
||||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||||
@@ -45,6 +44,7 @@ class FirTypeResolveTransformer(val superTypesOnly: Boolean = false) : FirTransf
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
packageFqName = file.packageFqName
|
packageFqName = file.packageFqName
|
||||||
|
this.file = file
|
||||||
return super.transformFile(file, data)
|
return super.transformFile(file, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +93,16 @@ class FirTypeResolveTransformer(val superTypesOnly: Boolean = false) : FirTransf
|
|||||||
return super.transformTypeAlias(typeAlias, data)
|
return super.transformTypeAlias(typeAlias, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun transformNamedFunction(namedFunction: FirNamedFunction, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||||
|
scope = FirCompositeScope(mutableListOf(scope))
|
||||||
|
scope.scopes += FirFunctionTypeParameterScope(file, classLikeName, namedFunction.name, namedFunction.session)
|
||||||
|
|
||||||
|
val result = super.transformNamedFunction(namedFunction, data)
|
||||||
|
scope = scope.scopes[0] as FirCompositeScope
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
override fun transformType(type: FirType, data: Nothing?): CompositeTransformResult<FirType> {
|
override fun transformType(type: FirType, data: Nothing?): CompositeTransformResult<FirType> {
|
||||||
val typeResolver = FirTypeResolver.getInstance(type.session)
|
val typeResolver = FirTypeResolver.getInstance(type.session)
|
||||||
type.transformChildren(this, null)
|
type.transformChildren(this, null)
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.scopes.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationContainer
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirNamedFunction
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
|
class FirFunctionTypeParameterScope(
|
||||||
|
val file: FirFile,
|
||||||
|
val className: FqName,
|
||||||
|
val functionName: Name,
|
||||||
|
val session: FirSession
|
||||||
|
) : FirScope {
|
||||||
|
|
||||||
|
private val firProvider = FirProvider.getInstance(session)
|
||||||
|
|
||||||
|
val typeParameterContainer = when {
|
||||||
|
className.isRoot -> file
|
||||||
|
else -> firProvider.getFirClassifierByFqName(ClassId(file.packageFqName, className, false)) as? FirDeclarationContainer
|
||||||
|
}?.declarations?.filterIsInstance<FirNamedFunction>()?.find { it.name == functionName }
|
||||||
|
|
||||||
|
val typeParameters = typeParameterContainer?.typeParameters.orEmpty().groupBy { it.name }
|
||||||
|
|
||||||
|
override fun processClassifiersByName(name: Name, processor: (ConeSymbol) -> Boolean): Boolean {
|
||||||
|
val matchedTypeParameters = typeParameters[name] ?: return true
|
||||||
|
|
||||||
|
return matchedTypeParameters.all { processor(it.symbol) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -305,6 +305,9 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
|||||||
|
|
||||||
override fun visitTypeParameter(typeParameter: FirTypeParameter) {
|
override fun visitTypeParameter(typeParameter: FirTypeParameter) {
|
||||||
typeParameter.annotations.renderAnnotations()
|
typeParameter.annotations.renderAnnotations()
|
||||||
|
if (typeParameter.isReified) {
|
||||||
|
print("reified ")
|
||||||
|
}
|
||||||
typeParameter.variance.renderVariance()
|
typeParameter.variance.renderVariance()
|
||||||
print(typeParameter.name)
|
print(typeParameter.name)
|
||||||
if (typeParameter.bounds.isNotEmpty()) {
|
if (typeParameter.bounds.isNotEmpty()) {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
interface Any
|
||||||
|
|
||||||
|
inline fun <reified T : Any> Any.safeAs(): T? = this as? T
|
||||||
|
|
||||||
|
abstract class Summator {
|
||||||
|
abstract fun <T> plus(first: T, second: T): T
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
FILE: genericFunctions.kt
|
||||||
|
(resolved) public? abstract interface Any() {
|
||||||
|
}
|
||||||
|
<reified T : Any> public? final? inline function safeAsR/Any/.(): R/T/ {
|
||||||
|
STUB
|
||||||
|
}
|
||||||
|
(resolved) public? abstract class Summator() {
|
||||||
|
<T> public? abstract function plus(first: R/T/, second: R/T/): R/T/
|
||||||
|
|
||||||
|
}
|
||||||
@@ -31,6 +31,12 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("genericFunctions.kt")
|
||||||
|
public void testGenericFunctions() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/resolve/genericFunctions.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("NestedOfAliasedType.kt")
|
@TestMetadata("NestedOfAliasedType.kt")
|
||||||
public void testNestedOfAliasedType() throws Exception {
|
public void testNestedOfAliasedType() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/resolve/NestedOfAliasedType.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/fir/resolve/NestedOfAliasedType.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user