FIR: Introduce NAMED_PARAMETER_NOT_FOUND diagnostic

This commit is contained in:
Denis.Zharkov
2021-04-02 13:37:59 +03:00
committed by TeamCityServer
parent 2d42e64c17
commit 0637748f10
31 changed files with 103 additions and 66 deletions
@@ -571,6 +571,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt");
}
@TestMetadata("noParameterForName.kt")
public void testNoParameterForName() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/noParameterForName.kt");
}
@TestMetadata("operatorsOverLiterals.kt")
public void testOperatorsOverLiterals() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/operatorsOverLiterals.kt");
@@ -0,0 +1,6 @@
FILE: noParameterForName.kt
public final fun foo(x: R|kotlin/Int|): R|kotlin/Unit| {
}
public final fun bar(): R|kotlin/Unit| {
<Inapplicable(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR): /foo>#(y = Int(1))
}
@@ -0,0 +1,5 @@
fun foo(x: Int) {}
fun bar() {
foo(<!NAMED_PARAMETER_NOT_FOUND!>y<!> = 1<!NO_VALUE_FOR_PARAMETER!>)<!>
}
@@ -13,5 +13,5 @@ fun test() {
foo(second = 0.0, first = 0, fourth = ""<!NO_VALUE_FOR_PARAMETER!>)<!>
<!INAPPLICABLE_CANDIDATE!>foo<!>(first = 0.0, second = 0, third = "", fourth = false)
foo(first = 0, second = 0.0, third = false, fourth = "", <!ARGUMENT_PASSED_TWICE!>first<!> = 1)
foo(0, 0.0, false, foth = ""<!NO_VALUE_FOR_PARAMETER!>)<!>
foo(0, 0.0, false, <!NAMED_PARAMETER_NOT_FOUND!>foth<!> = ""<!NO_VALUE_FOR_PARAMETER!>)<!>
}
@@ -671,6 +671,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt");
}
@Test
@TestMetadata("noParameterForName.kt")
public void testNoParameterForName() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/noParameterForName.kt");
}
@Test
@TestMetadata("operatorsOverLiterals.kt")
public void testOperatorsOverLiterals() throws Exception {
@@ -675,6 +675,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt");
}
@Test
@TestMetadata("noParameterForName.kt")
public void testNoParameterForName() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/arguments/noParameterForName.kt");
}
@Test
@TestMetadata("operatorsOverLiterals.kt")
public void testOperatorsOverLiterals() throws Exception {
@@ -233,6 +233,10 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
val NO_VALUE_FOR_PARAMETER by error<FirSourceElement, KtElement>(PositioningStrategy.VALUE_ARGUMENTS) {
parameter<FirValueParameter>("violatedParameter")
}
val NAMED_PARAMETER_NOT_FOUND by error<FirSourceElement, KtValueArgument>(PositioningStrategy.NAME_OF_NAMED_ARGUMENT) {
parameter<String>("name")
}
}
val AMBIGUITY by object : DiagnosticGroup("Ambiguity") {
@@ -187,6 +187,7 @@ object FirErrors {
val ARGUMENT_PASSED_TWICE by error0<FirSourceElement, KtValueArgument>(SourceElementPositioningStrategies.NAME_OF_NAMED_ARGUMENT)
val TOO_MANY_ARGUMENTS by error1<FirSourceElement, PsiElement, FirCallableDeclaration<*>>()
val NO_VALUE_FOR_PARAMETER by error1<FirSourceElement, KtElement, FirValueParameter>(SourceElementPositioningStrategies.VALUE_ARGUMENTS)
val NAMED_PARAMETER_NOT_FOUND by error1<FirSourceElement, KtValueArgument, String>(SourceElementPositioningStrategies.NAME_OF_NAMED_ARGUMENT)
// Ambiguity
val OVERLOAD_RESOLUTION_AMBIGUITY by error1<FirSourceElement, PsiElement, Collection<AbstractFirBasedSymbol<*>>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
@@ -131,6 +131,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_VARARG_P
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MUST_BE_INITIALIZED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NAMED_ARGUMENTS_NOT_ALLOWED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NAMED_PARAMETER_NOT_FOUND
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NESTED_CLASS_NOT_ALLOWED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NONE_APPLICABLE
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY
@@ -394,6 +395,7 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
map.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES)
map.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter")
map.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter ''{0}''", NAME)
map.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", TO_STRING)
// Ambiguity
map.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity between candidates: {0}", SYMBOLS)
@@ -141,6 +141,10 @@ private fun mapInapplicableCandidateError(
is ArgumentPassedTwice -> FirErrors.ARGUMENT_PASSED_TWICE.on(rootCause.argument.source)
is TooManyArguments -> FirErrors.TOO_MANY_ARGUMENTS.on(rootCause.argument.source ?: source, rootCause.function)
is NoValueForParameter -> FirErrors.NO_VALUE_FOR_PARAMETER.on(qualifiedAccessSource ?: source, rootCause.valueParameter)
is NameNotFound -> FirErrors.NAMED_PARAMETER_NOT_FOUND.on(
rootCause.argument.source ?: source,
rootCause.argument.name.asString()
)
else -> null
}
}.ifEmpty { listOf(FirErrors.INAPPLICABLE_CANDIDATE.on(source, diagnostic.candidate.symbol)) }
@@ -120,10 +120,8 @@ private class FirCallArgumentsProcessor(
fun processArgumentsInParenthesis(arguments: List<FirExpression>) {
for (argument in arguments) {
val argumentName = argument.argumentName
// process position argument
if (argumentName == null) {
if (argument !is FirNamedArgumentExpression) {
if (processPositionArgument(argument)) {
state = State.VARARG_POSITION
}
@@ -134,7 +132,7 @@ private class FirCallArgumentsProcessor(
completeVarargPositionArguments()
}
processNamedArgument(argument, argumentName)
processNamedArgument(argument)
}
}
if (state == State.VARARG_POSITION) {
@@ -168,14 +166,14 @@ private class FirCallArgumentsProcessor(
}
}
private fun processNamedArgument(argument: FirExpression, name: Name) {
private fun processNamedArgument(argument: FirNamedArgumentExpression) {
forbiddenNamedArgumentsTarget?.let {
addDiagnostic(NamedArgumentNotAllowed(argument, function, it))
}
val stateAllowsMixedNamedAndPositionArguments = state != State.NAMED_ONLY_ARGUMENTS
state = State.NAMED_ONLY_ARGUMENTS
val parameter = findParameterByName(argument, name) ?: return
val parameter = findParameterByName(argument) ?: return
result[parameter]?.let {
addDiagnostic(ArgumentPassedTwice(argument, parameter, it))
@@ -257,8 +255,8 @@ private class FirCallArgumentsProcessor(
return nameToParameter!![name]
}
private fun findParameterByName(argument: FirExpression, name: Name): FirValueParameter? {
val parameter = getParameterByName(name)
private fun findParameterByName(argument: FirNamedArgumentExpression): FirValueParameter? {
val parameter = getParameterByName(argument.name)
// TODO
// if (descriptor is CallableMemberDescriptor && descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.*
@@ -51,9 +52,9 @@ class NoValueForParameter(
) : ResolutionDiagnostic(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR)
class NameNotFound(
override val argument: FirExpression,
val argument: FirNamedArgumentExpression,
val function: FirFunction<*>
) : InapplicableArgumentDiagnostic()
) : ResolutionDiagnostic(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR)
object InapplicableCandidate : ResolutionDiagnostic(INAPPLICABLE)