FirDefaultParametersResolver: process imported from objects properly
#KT-49083 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
c5a4a5de42
commit
09bc729b0e
+6
@@ -5069,6 +5069,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/DailyAggregatedDoubleFactor.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/DailyAggregatedDoubleFactor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("defaultParameterFromBase.kt")
|
||||||
|
public void testDefaultParameterFromBase() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/defaultParameterFromBase.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("EnumWithToString.kt")
|
@TestMetadata("EnumWithToString.kt")
|
||||||
public void testEnumWithToString() throws Exception {
|
public void testEnumWithToString() throws Exception {
|
||||||
|
|||||||
Vendored
+22
@@ -0,0 +1,22 @@
|
|||||||
|
FILE: defaultParameterFromBase.kt
|
||||||
|
public open class Base : R|kotlin/Any| {
|
||||||
|
public constructor(): R|Base| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public open fun foo(arg: R|kotlin/Int|, def: R|kotlin/String| = String()): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final object Derived : R|Base| {
|
||||||
|
private constructor(): R|Derived| {
|
||||||
|
super<R|Base|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final override fun foo(arg: R|kotlin/Int|, def: R|kotlin/String|): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final fun test(): R|kotlin/Unit| {
|
||||||
|
Q|Derived|.R|/Derived.foo|(Int(42))
|
||||||
|
}
|
||||||
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import Derived.foo
|
||||||
|
|
||||||
|
open class Base {
|
||||||
|
open fun foo(arg: Int, def: String = "") {}
|
||||||
|
}
|
||||||
|
object Derived : Base() {
|
||||||
|
override fun foo(arg: Int, def: String) {}
|
||||||
|
}
|
||||||
|
fun test() {
|
||||||
|
foo(42) // No value passed for parameter 'def'
|
||||||
|
}
|
||||||
+6
@@ -5069,6 +5069,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/DailyAggregatedDoubleFactor.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/DailyAggregatedDoubleFactor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("defaultParameterFromBase.kt")
|
||||||
|
public void testDefaultParameterFromBase() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/defaultParameterFromBase.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("EnumWithToString.kt")
|
@TestMetadata("EnumWithToString.kt")
|
||||||
public void testEnumWithToString() throws Exception {
|
public void testEnumWithToString() throws Exception {
|
||||||
|
|||||||
+6
@@ -5069,6 +5069,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/DailyAggregatedDoubleFactor.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/DailyAggregatedDoubleFactor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("defaultParameterFromBase.kt")
|
||||||
|
public void testDefaultParameterFromBase() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/defaultParameterFromBase.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("EnumWithToString.kt")
|
@TestMetadata("EnumWithToString.kt")
|
||||||
public void testEnumWithToString() throws Exception {
|
public void testEnumWithToString() throws Exception {
|
||||||
|
|||||||
+18
-8
@@ -8,26 +8,36 @@ package org.jetbrains.kotlin.fir.resolve
|
|||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractImportingScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
|
||||||
|
|
||||||
class FirDefaultParametersResolver : FirSessionComponent {
|
class FirDefaultParametersResolver : FirSessionComponent {
|
||||||
fun declaresDefaultValue(
|
fun declaresDefaultValue(
|
||||||
|
session: FirSession,
|
||||||
|
scopeSession: ScopeSession,
|
||||||
valueParameter: FirValueParameter,
|
valueParameter: FirValueParameter,
|
||||||
function: FirFunction,
|
function: FirFunction,
|
||||||
originScope: FirScope?,
|
originScope: FirScope?,
|
||||||
index: Int,
|
index: Int,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (valueParameter.defaultValue != null) return true
|
if (valueParameter.defaultValue != null) return true
|
||||||
if (originScope !is FirTypeScope) return false
|
if (function !is FirSimpleFunction) return false
|
||||||
val symbol = function.symbol as? FirNamedFunctionSymbol ?: return false
|
val symbol = function.symbol
|
||||||
|
val typeScope = when (originScope) {
|
||||||
|
is FirTypeScope -> originScope
|
||||||
|
// imported from object case
|
||||||
|
is FirAbstractImportingScope -> {
|
||||||
|
val containingClass = function.getContainingClass(session) ?: return false
|
||||||
|
containingClass.scopeForClass(ConeSubstitutor.Empty, session, scopeSession)
|
||||||
|
}
|
||||||
|
else -> return false
|
||||||
|
}
|
||||||
var result = false
|
var result = false
|
||||||
|
|
||||||
originScope.processOverriddenFunctions(symbol) { overridden ->
|
typeScope.processOverriddenFunctions(symbol) { overridden ->
|
||||||
if (overridden.fir.valueParameters[index].defaultValue != null) {
|
if (overridden.fir.valueParameters[index].defaultValue != null) {
|
||||||
result = true
|
result = true
|
||||||
return@processOverriddenFunctions ProcessorAction.STOP
|
return@processOverriddenFunctions ProcessorAction.STOP
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ private fun initialTypeOfCandidate(candidate: Candidate, typeRef: FirResolvedTyp
|
|||||||
return candidate.substitutor.substituteOrSelf(typeRef.type)
|
return candidate.substitutor.substituteOrSelf(typeRef.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirCallableDeclaration.getContainingClass(session: FirSession): FirRegularClass? = this.containingClassForStaticMemberAttr?.let { lookupTag ->
|
fun FirCallableDeclaration.getContainingClass(session: FirSession): FirRegularClass? = this.containingClass()?.let { lookupTag ->
|
||||||
session.symbolProvider.getSymbolByLookupTag(lookupTag)?.fir as? FirRegularClass
|
session.symbolProvider.getSymbolByLookupTag(lookupTag)?.fir as? FirRegularClass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-6
@@ -259,12 +259,15 @@ private class FirCallArgumentsProcessor(
|
|||||||
|
|
||||||
for ((index, parameter) in parameters.withIndex()) {
|
for ((index, parameter) in parameters.withIndex()) {
|
||||||
if (!result.containsKey(parameter)) {
|
if (!result.containsKey(parameter)) {
|
||||||
if (bodyResolveComponents.session.defaultParameterResolver.declaresDefaultValue(parameter, function, originScope, index)) {
|
when {
|
||||||
result[parameter] = ResolvedCallArgument.DefaultArgument
|
bodyResolveComponents.session.defaultParameterResolver.declaresDefaultValue(
|
||||||
} else if (parameter.isVararg) {
|
useSiteSession, bodyResolveComponents.scopeSession, parameter, function, originScope, index
|
||||||
result[parameter] = ResolvedCallArgument.VarargArgument(emptyList())
|
) ->
|
||||||
} else {
|
result[parameter] = ResolvedCallArgument.DefaultArgument
|
||||||
addDiagnostic(NoValueForParameter(parameter, function))
|
parameter.isVararg ->
|
||||||
|
result[parameter] = ResolvedCallArgument.VarargArgument(emptyList())
|
||||||
|
else ->
|
||||||
|
addDiagnostic(NoValueForParameter(parameter, function))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user