[FIR] Throw REDECLARATION for duplicated value parameters in function
Add new test file
This commit is contained in:
+6
@@ -22805,6 +22805,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclaredValueParameters.kt")
|
||||
public void testRedeclaredValueParameters() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/redeclarations/RedeclaredValueParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclaringPrivateToFile.kt")
|
||||
public void testRedeclaringPrivateToFile() throws Exception {
|
||||
|
||||
+6
@@ -22805,6 +22805,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclaredValueParameters.kt")
|
||||
public void testRedeclaredValueParameters() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/redeclarations/RedeclaredValueParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclaringPrivateToFile.kt")
|
||||
public void testRedeclaringPrivateToFile() throws Exception {
|
||||
|
||||
+27
-7
@@ -5,19 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.diagnostics.PositioningStrategies
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationInspector
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationPresenter
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.SourceElementPositioningStrategies
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInner
|
||||
import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.getOuterClass
|
||||
import org.jetbrains.kotlin.fir.scopes.PACKAGE_MEMBER
|
||||
@@ -27,8 +22,6 @@ import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.util.ListMultimap
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -224,6 +217,10 @@ object FirConflictsChecker : FirBasicDeclarationChecker() {
|
||||
when (declaration) {
|
||||
is FirFile -> checkFile(declaration, inspector, context)
|
||||
is FirRegularClass -> checkRegularClass(declaration, inspector)
|
||||
is FirFunction -> {
|
||||
checkConflictingValueParameters(declaration, context, reporter)
|
||||
return
|
||||
}
|
||||
else -> return
|
||||
}
|
||||
|
||||
@@ -251,6 +248,29 @@ object FirConflictsChecker : FirBasicDeclarationChecker() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkConflictingValueParameters(function: FirFunction, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val multimap = ListMultimap<Name, FirValueParameter>()
|
||||
for (parameter in function.valueParameters) {
|
||||
if (!parameter.name.isSpecial) {
|
||||
multimap.put(parameter.name, parameter)
|
||||
}
|
||||
}
|
||||
for (key in multimap.keys) {
|
||||
val parameters = multimap[key]
|
||||
if (parameters.size > 1) {
|
||||
val symbols = parameters.map { it.symbol }
|
||||
for (parameter in parameters) {
|
||||
reporter.reportOn(
|
||||
parameter.source,
|
||||
FirErrors.REDECLARATION,
|
||||
symbols,
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkFile(file: FirFile, inspector: DeclarationInspector, context: CheckerContext) {
|
||||
val packageMemberScope: FirPackageMemberScope = context.sessionHolder.scopeSession.getOrBuild(file.packageFqName, PACKAGE_MEMBER) {
|
||||
FirPackageMemberScope(file.packageFqName, context.sessionHolder.session)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
data class A1(val <!REDECLARATION!>x<!>: Int, val y: String, val <!REDECLARATION!>x<!>: Int) {
|
||||
val z = ""
|
||||
}
|
||||
|
||||
data class A2(val <!REDECLARATION!>x<!>: Int, val y: String) {
|
||||
val <!REDECLARATION!>x<!> = ""
|
||||
}
|
||||
|
||||
data class A3(<!REDECLARATION!>val<!SYNTAX!><!> :Int<!>, <!REDECLARATION!>val<!SYNTAX!><!> : Int<!>)
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
data class A1(val <!REDECLARATION, REDECLARATION, REDECLARATION!>x<!>: Int, val y: String, val <!REDECLARATION, REDECLARATION, REDECLARATION!>x<!>: Int) {
|
||||
val z = ""
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ fun bar() {
|
||||
_ checkType { _<String>() }
|
||||
}
|
||||
|
||||
foo { `_`, `_` ->
|
||||
foo { <!REDECLARATION!>`_`<!>, <!REDECLARATION!>`_`<!> ->
|
||||
_ checkType { _<String>() }
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun test(<!REDECLARATION!>a<!>: Int, <!REDECLARATION!>a<!>: String) {}
|
||||
|
||||
fun test2(block: (Int, String) -> Unit) { }
|
||||
|
||||
fun main() {
|
||||
test2 { <!REDECLARATION!>b<!>, <!REDECLARATION!>b<!> -> ; }
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun test(<!REDECLARATION, REDECLARATION!>a<!>: Int, <!REDECLARATION, REDECLARATION!>a<!>: String) {}
|
||||
|
||||
fun test2(block: (Int, String) -> Unit) { }
|
||||
|
||||
fun main() {
|
||||
test2 { <!REDECLARATION, REDECLARATION!>b<!>, <!REDECLARATION, REDECLARATION!>b<!> -> ; }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
public fun test(/*0*/ a: kotlin.Int, /*1*/ a: kotlin.String): kotlin.Unit
|
||||
public fun test2(/*0*/ block: (kotlin.Int, kotlin.String) -> kotlin.Unit): kotlin.Unit
|
||||
Generated
+6
@@ -22811,6 +22811,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclaredValueParameters.kt")
|
||||
public void testRedeclaredValueParameters() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/redeclarations/RedeclaredValueParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("RedeclaringPrivateToFile.kt")
|
||||
public void testRedeclaringPrivateToFile() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user