diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index f8c56211af4..41627f99923 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -3322,6 +3322,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt"); } + @Test + @TestMetadata("genericTypealiasInLhs.kt") + public void testGenericTypealiasInLhs() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt"); + } + @Test @TestMetadata("kt15439_completeCall.kt") public void testKt15439_completeCall() throws Exception { @@ -4039,6 +4045,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.kt"); } + @Test + @TestMetadata("boundViolated.kt") + public void testBoundViolated() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt"); + } + @Test @TestMetadata("dependOnArgumentType.kt") public void testDependOnArgumentType() throws Exception { @@ -4069,6 +4081,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt"); } + @Test + @TestMetadata("incorrectNumberOfTypeArguments.kt") + public void testIncorrectNumberOfTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt"); + } + @Test @TestMetadata("kt10968.kt") public void testKt10968() throws Exception { @@ -5374,6 +5392,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt"); } + @Test + @TestMetadata("parameterizedTypeAlias.kt") + public void testParameterizedTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt"); + } + @Test @TestMetadata("qualifiedClassLiteral.kt") public void testQualifiedClassLiteral() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 9fca61b177e..44cbf727859 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -3322,6 +3322,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt"); } + @Test + @TestMetadata("genericTypealiasInLhs.kt") + public void testGenericTypealiasInLhs() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt"); + } + @Test @TestMetadata("kt15439_completeCall.kt") public void testKt15439_completeCall() throws Exception { @@ -4039,6 +4045,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.kt"); } + @Test + @TestMetadata("boundViolated.kt") + public void testBoundViolated() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt"); + } + @Test @TestMetadata("dependOnArgumentType.kt") public void testDependOnArgumentType() throws Exception { @@ -4069,6 +4081,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt"); } + @Test + @TestMetadata("incorrectNumberOfTypeArguments.kt") + public void testIncorrectNumberOfTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt"); + } + @Test @TestMetadata("kt10968.kt") public void testKt10968() throws Exception { @@ -5374,6 +5392,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt"); } + @Test + @TestMetadata("parameterizedTypeAlias.kt") + public void testParameterizedTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt"); + } + @Test @TestMetadata("qualifiedClassLiteral.kt") public void testQualifiedClassLiteral() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 1dec0524e4a..7ad47c13a4e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -3322,6 +3322,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt"); } + @Test + @TestMetadata("genericTypealiasInLhs.kt") + public void testGenericTypealiasInLhs() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt"); + } + @Test @TestMetadata("kt15439_completeCall.kt") public void testKt15439_completeCall() throws Exception { @@ -4039,6 +4045,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.kt"); } + @Test + @TestMetadata("boundViolated.kt") + public void testBoundViolated() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt"); + } + @Test @TestMetadata("dependOnArgumentType.kt") public void testDependOnArgumentType() throws Exception { @@ -4069,6 +4081,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt"); } + @Test + @TestMetadata("incorrectNumberOfTypeArguments.kt") + public void testIncorrectNumberOfTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt"); + } + @Test @TestMetadata("kt10968.kt") public void testKt10968() throws Exception { @@ -5374,6 +5392,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt"); } + @Test + @TestMetadata("parameterizedTypeAlias.kt") + public void testParameterizedTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt"); + } + @Test @TestMetadata("qualifiedClassLiteral.kt") public void testQualifiedClassLiteral() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index ad28894688c..fe0c183b532 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -3328,6 +3328,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt"); } + @Test + @TestMetadata("genericTypealiasInLhs.kt") + public void testGenericTypealiasInLhs() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt"); + } + @Test @TestMetadata("kt15439_completeCall.kt") public void testKt15439_completeCall() throws Exception { @@ -4045,6 +4051,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.kt"); } + @Test + @TestMetadata("boundViolated.kt") + public void testBoundViolated() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt"); + } + @Test @TestMetadata("dependOnArgumentType.kt") public void testDependOnArgumentType() throws Exception { @@ -4075,6 +4087,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt"); } + @Test + @TestMetadata("incorrectNumberOfTypeArguments.kt") + public void testIncorrectNumberOfTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt"); + } + @Test @TestMetadata("kt10968.kt") public void testKt10968() throws Exception { @@ -5380,6 +5398,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt"); } + @Test + @TestMetadata("parameterizedTypeAlias.kt") + public void testParameterizedTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt"); + } + @Test @TestMetadata("qualifiedClassLiteral.kt") public void testQualifiedClassLiteral() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt index a43167b8ed6..311d645e35b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt @@ -168,4 +168,9 @@ object CommonExpressionCheckers : ExpressionCheckers() { get() = setOf( FirReceiverAccessBeforeSuperCallChecker, ) + + override val callableReferenceAccessCheckers: Set + get() = setOf( + FirTypeArgumentsOfQualifierOfCallableReferenceChecker, + ) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt index 267a7e624cc..d948363714d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor +import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.resolve.withCombinedAttributesFrom import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol @@ -72,10 +73,20 @@ private fun checkUpperBoundViolated( ) } -private class FE10LikeConeSubstitutor( +/** + * This substitutor replaces type projections with type of this projection + * Star projections are replaced with Any? + */ +internal class FE10LikeConeSubstitutor( private val substitution: Map, useSiteSession: FirSession ) : AbstractConeSubstitutor(useSiteSession.typeContext) { + constructor( + typeParameters: List, + typeArguments: List, + useSiteSession: FirSession + ) : this(typeParameters.zip(typeArguments).toMap(), useSiteSession) + override fun substituteType(type: ConeKotlinType): ConeKotlinType? { if (type !is ConeTypeParameterType) return null val projection = substitution[type.lookupTag.symbol] ?: return null @@ -134,7 +145,26 @@ private class OriginalProjectionTypeAttribute(val data: ConeTypeProjection) : Co get() = OriginalProjectionTypeAttribute::class } -private val ConeAttributes.originalProjection: OriginalProjectionTypeAttribute? by ConeAttributes.attributeAccessor() +private val ConeAttributes.originalProjection: OriginalProjectionTypeAttribute? by ConeAttributes.attributeAccessor() + +fun List.toTypeArgumentsWithSourceInfo(): List { + return map { firTypeProjection -> + firTypeProjection.toConeTypeProjection().withSource( + FirTypeRefSource((firTypeProjection as? FirTypeProjectionWithVariance)?.typeRef, firTypeProjection.source) + ) + } +} + +fun createSubstitutorForUpperBoundViolationCheck( + typeParameters: List, + typeArguments: List, + session: FirSession +): ConeSubstitutor { + return substitutorByMap( + typeParameters.withIndex().associate { Pair(it.value, typeArguments[it.index] as ConeKotlinType) }, + session, + ) +} fun checkUpperBoundViolated( context: CheckerContext, @@ -216,7 +246,7 @@ private class SourceAttribute(private val data: FirTypeRefSource) : ConeAttribut get() = SourceAttribute::class } -private val ConeAttributes.sourceAttribute: SourceAttribute? by ConeAttributes.attributeAccessor() +private val ConeAttributes.sourceAttribute: SourceAttribute? by ConeAttributes.attributeAccessor() fun ConeTypeProjection.withSource(source: FirTypeRefSource?): ConeTypeProjection { return when { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirTypeArgumentsOfQualifierOfCallableReferenceChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirTypeArgumentsOfQualifierOfCallableReferenceChecker.kt new file mode 100644 index 00000000000..d4b4bd766fc --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirTypeArgumentsOfQualifierOfCallableReferenceChecker.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.analysis.checkers.expression + +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.checkers.FE10LikeConeSubstitutor +import org.jetbrains.kotlin.fir.analysis.checkers.checkUpperBoundViolated +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol +import org.jetbrains.kotlin.fir.analysis.checkers.toTypeArgumentsWithSourceInfo +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess +import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.resolve.fullyExpandedType +import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol +import org.jetbrains.kotlin.fir.types.constructType + +object FirTypeArgumentsOfQualifierOfCallableReferenceChecker : FirCallableReferenceAccessChecker() { + override fun check(expression: FirCallableReferenceAccess, context: CheckerContext, reporter: DiagnosticReporter) { + val lhs = expression.explicitReceiver as? FirResolvedQualifier ?: return + val correspondingDeclaration = lhs.symbol ?: return + + var typeArgumentsWithSourceInfo = lhs.typeArguments.toTypeArgumentsWithSourceInfo() + var typeParameterSymbols = correspondingDeclaration.typeParameterSymbols + if (typeParameterSymbols.size != typeArgumentsWithSourceInfo.size) { + reporter.reportOn( + lhs.source, + FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS, + correspondingDeclaration.typeParameterSymbols.size, + correspondingDeclaration, + context + ) + return + } + + if (correspondingDeclaration is FirTypeAliasSymbol) { + val qualifierType = correspondingDeclaration.constructType(typeArgumentsWithSourceInfo.toTypedArray(), isNullable = false) + val expandedLhsType = qualifierType.fullyExpandedType(context.session) + typeArgumentsWithSourceInfo = expandedLhsType.typeArguments.toList() + + val expandedClassSymbol = correspondingDeclaration.resolvedExpandedTypeRef.toRegularClassSymbol(context.session) ?: return + typeParameterSymbols = expandedClassSymbol.typeParameterSymbols + } + + val substitutor = FE10LikeConeSubstitutor(typeParameterSymbols, typeArgumentsWithSourceInfo, context.session) + checkUpperBoundViolated( + context, + reporter, + typeParameterSymbols, + typeArgumentsWithSourceInfo, + substitutor, + ) + } +} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt index 31a7b2ed5d6..3b1ec513597 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirUpperBoundViolatedExpressionChecker.kt @@ -10,14 +10,15 @@ import org.jetbrains.kotlin.fir.analysis.checkers.FirTypeRefSource import org.jetbrains.kotlin.fir.analysis.checkers.checkUpperBoundViolated import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.withSource +import org.jetbrains.kotlin.fir.analysis.checkers.createSubstitutorForUpperBoundViolationCheck +import org.jetbrains.kotlin.fir.analysis.checkers.toTypeArgumentsWithSourceInfo import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression -import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.references.FirResolvedErrorReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference +import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableWrongReceiver import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.isTypeAliasedConstructor -import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol @@ -54,11 +55,7 @@ object FirUpperBoundViolatedExpressionChecker : FirQualifiedAccessExpressionChec typeParameters = (constructedType.toSymbol(context.session) as? FirRegularClassSymbol)?.typeParameterSymbols ?: return } else { - typeArguments = expression.typeArguments.map { firTypeProjection -> - firTypeProjection.toConeTypeProjection().withSource( - FirTypeRefSource((firTypeProjection as? FirTypeProjectionWithVariance)?.typeRef, firTypeProjection.source) - ) - } + typeArguments = expression.typeArguments.toTypeArgumentsWithSourceInfo() typeParameters = calleeSymbol?.typeParameterSymbols ?: return } @@ -70,8 +67,9 @@ object FirUpperBoundViolatedExpressionChecker : FirQualifiedAccessExpressionChec if (typeArguments.size != typeParameters.size) return - val substitutor = substitutorByMap( - typeParameters.withIndex().associate { Pair(it.value, typeArguments[it.index] as ConeKotlinType) }, + val substitutor = createSubstitutorForUpperBoundViolationCheck( + typeParameters, + typeArguments, context.session, ) diff --git a/compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt deleted file mode 100644 index a074814bc15..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/bareType.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) - * - * SPEC VERSION: 0.1-220 - * PRIMARY LINKS: expressions, call-and-property-access-expressions, callable-references -> paragraph 3 -> sentence 1 - */ -fun f1() = Map::hashCode -fun f2() = Map.Entry::hashCode - -class Outer { - inner class Inner -} - -fun f3() = Outer.Inner::hashCode diff --git a/compiler/testData/diagnostics/tests/callableReference/bareType.kt b/compiler/testData/diagnostics/tests/callableReference/bareType.kt index 9ac0c282578..b6847ada8aa 100644 --- a/compiler/testData/diagnostics/tests/callableReference/bareType.kt +++ b/compiler/testData/diagnostics/tests/callableReference/bareType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL /* * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) * diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt b/compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt new file mode 100644 index 00000000000..13285f9b764 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +// WITH_STDLIB +// ISSUE: KT-56187 + +class Foo { + val value: String = "OK" + val genericValue: T = null!! +} + +fun main() { + val a = Foo<String>::value + val b = Foo<String>::genericValue +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.fir.kt new file mode 100644 index 00000000000..8ebba7d863b --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.fir.kt @@ -0,0 +1,14 @@ +// WITH_STDLIB +// ISSUE: KT-56186 + +class Foo { + val value: String = "OK" + val genericValue: Triple = TODO() +} + +fun test_1() { + val a = Foo::value + val b = Foo::value + val c = Foo::genericValue + val d = Foo::genericValue +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt b/compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt new file mode 100644 index 00000000000..6185bdfc547 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt @@ -0,0 +1,14 @@ +// WITH_STDLIB +// ISSUE: KT-56186 + +class Foo { + val value: String = "OK" + val genericValue: Triple = TODO() +} + +fun test_1() { + val a = Foo::value + val b = Foo::value + val c = Foo::genericValue + val d = Foo::genericValue +} diff --git a/compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.fir.kt b/compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.fir.kt new file mode 100644 index 00000000000..bd6b65d816c --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.fir.kt @@ -0,0 +1,170 @@ +class Some { fun foo() {} } + +typealias SomeAlias = Some +typealias SomeUnusedAlias = Some + +fun test_1() { + Some::foo + Some::foo + + SomeAlias::foo + SomeAlias::foo + + SomeUnusedAlias::foo + SomeUnusedAlias::foo + SomeUnusedAlias::foo + SomeUnusedAlias::foo + SomeUnusedAlias<*>::foo + SomeUnusedAlias::foo +} + +// ---------------------------------------------------------------- + +class Inv { fun foo() {} } + +typealias InvAlias = Inv +typealias InvUnusedCorrectAlias = Inv +typealias InvUnusedIncorrectAlias = Inv<Int> +typealias InvSpecificAlias = Inv + +fun test_2() { + Inv::foo + Inv<Int>::foo + Inv<*>::foo + Inv<out Int>::foo + Inv::foo + Inv::foo + Inv::foo + + InvAlias::foo + InvAlias<Int>::foo + InvAlias<*>::foo + InvAlias<out Int>::foo + InvAlias::foo + InvAlias::foo + InvAlias::foo + + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias<*>::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias<*>::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + + InvSpecificAlias::foo + InvSpecificAlias::foo +} + +// ---------------------------------------------------------------- + +class BoundedPair { fun foo() {} } + +typealias BoundedPairAlias = BoundedPair +typealias BoundedPairInverted = BoundedPair +typealias BoundedPairFirstFixedAlias = BoundedPair +typealias BoundedPairSecondFixedAlias = BoundedPair +typealias BoundedPairFirstUnusedAlias = BoundedPair +typealias BoundedPairSecondUnusedAlias = BoundedPair +typealias BoundedPairBothAlias = BoundedPair +typealias BoundedPairSpecificAlias = BoundedPair + +fun test_3() { + BoundedPair::foo + BoundedPair<Int, Int>::foo + BoundedPair<*, *>::foo + BoundedPair::foo + BoundedPair<out Int, out Int>::foo + BoundedPair::foo + BoundedPair<in Int, in Int>::foo + BoundedPair::foo + BoundedPair::foo + + BoundedPairAlias::foo + BoundedPairAlias<Int, Int>::foo + BoundedPairAlias<*, *>::foo + BoundedPairAlias::foo + BoundedPairAlias<out Int, out Int>::foo + BoundedPairAlias::foo + BoundedPairAlias<in Int, in Int>::foo + BoundedPairAlias::foo + BoundedPairAlias::foo + + BoundedPairInvertedInt>::foo + BoundedPairInvertedInt>::foo + BoundedPairInverted<*, *>::foo + BoundedPairInvertedout Int>::foo + BoundedPairInvertedout Int>::foo + BoundedPairInvertedin Int>::foo + BoundedPairInvertedin Int>::foo + BoundedPairInverted::foo + BoundedPairInverted::foo + + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias<*>::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + + BoundedPairSecondFixedAlias<Int>::foo + BoundedPairSecondFixedAlias<Int>::foo + BoundedPairSecondFixedAlias<*>::foo + BoundedPairSecondFixedAlias::foo + BoundedPairSecondFixedAlias<out Int>::foo + BoundedPairSecondFixedAlias::foo + BoundedPairSecondFixedAlias<in Int>::foo + BoundedPairSecondFixedAlias::foo + BoundedPairSecondFixedAlias::foo + + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias<*, *>::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAlias<Int, Int>::foo + BoundedPairSecondUnusedAlias<*, *>::foo + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAlias<out Int, out Int>::foo + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAlias<in Int, in Int>::foo + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAlias::foo + + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias<*, *>::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias<*, *>::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo +} diff --git a/compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt b/compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt new file mode 100644 index 00000000000..bc6733e2352 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt @@ -0,0 +1,170 @@ +class Some { fun foo() {} } + +typealias SomeAlias = Some +typealias SomeUnusedAlias = Some + +fun test_1() { + Some::foo + Some::foo + + SomeAlias::foo + SomeAlias::foo + + SomeUnusedAlias::foo + SomeUnusedAlias::foo + SomeUnusedAlias::foo + SomeUnusedAlias::foo + SomeUnusedAlias<*>::foo + SomeUnusedAlias::foo +} + +// ---------------------------------------------------------------- + +class Inv { fun foo() {} } + +typealias InvAlias = Inv +typealias InvUnusedCorrectAlias = Inv +typealias InvUnusedIncorrectAlias = Inv<Int> +typealias InvSpecificAlias = Inv + +fun test_2() { + Inv::foo + Inv<Int>::foo + Inv<*>::foo + InvInt>::foo + Inv::foo + Inv::foo + Inv::foo + + InvAlias::foo + InvAlias<Int>::foo + InvAlias<*>::foo + InvAliasInt>::foo + InvAlias::foo + InvAlias::foo + InvAlias::foo + + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias<*>::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + InvUnusedCorrectAlias::foo + + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias<*>::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + InvUnusedIncorrectAlias::foo + + InvSpecificAlias::foo + InvSpecificAlias::foo +} + +// ---------------------------------------------------------------- + +class BoundedPair { fun foo() {} } + +typealias BoundedPairAlias = BoundedPair +typealias BoundedPairInverted = BoundedPair +typealias BoundedPairFirstFixedAlias = BoundedPair +typealias BoundedPairSecondFixedAlias = BoundedPair +typealias BoundedPairFirstUnusedAlias = BoundedPair +typealias BoundedPairSecondUnusedAlias = BoundedPair +typealias BoundedPairBothAlias = BoundedPair +typealias BoundedPairSpecificAlias = BoundedPair + +fun test_3() { + BoundedPair::foo + BoundedPair<Int, Int>::foo + BoundedPair<*, *>::foo + BoundedPair::foo + BoundedPairInt, out Int>::foo + BoundedPair::foo + BoundedPairInt, in Int>::foo + BoundedPair::foo + BoundedPair::foo + + BoundedPairAlias::foo + BoundedPairAlias<Int, Int>::foo + BoundedPairAlias<*, *>::foo + BoundedPairAlias::foo + BoundedPairAliasInt, out Int>::foo + BoundedPairAlias::foo + BoundedPairAliasInt, in Int>::foo + BoundedPairAlias::foo + BoundedPairAlias::foo + + BoundedPairInvertedInt>::foo + BoundedPairInvertedInt>::foo + BoundedPairInverted<*, *>::foo + BoundedPairInvertedInt>::foo + BoundedPairInvertedInt>::foo + BoundedPairInvertedInt>::foo + BoundedPairInvertedInt>::foo + BoundedPairInverted::foo + BoundedPairInverted::foo + + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias<*>::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + BoundedPairFirstFixedAlias::foo + + BoundedPairSecondFixedAlias<Int>::foo + BoundedPairSecondFixedAlias<Int>::foo + BoundedPairSecondFixedAlias<*>::foo + BoundedPairSecondFixedAlias::foo + BoundedPairSecondFixedAliasInt>::foo + BoundedPairSecondFixedAlias::foo + BoundedPairSecondFixedAliasInt>::foo + BoundedPairSecondFixedAlias::foo + BoundedPairSecondFixedAlias::foo + + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias<*, *>::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + BoundedPairFirstUnusedAlias::foo + + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAlias<Int, Int>::foo + BoundedPairSecondUnusedAlias<*, *>::foo + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAliasInt, out Int>::foo + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAliasInt, in Int>::foo + BoundedPairSecondUnusedAlias::foo + BoundedPairSecondUnusedAlias::foo + + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias<*, *>::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + BoundedPairBothAlias::foo + + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias<*, *>::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo + BoundedPairSpecificAlias::foo +} diff --git a/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt index ce57921a22f..bd0b2c133d2 100644 --- a/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt +++ b/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.fir.kt @@ -1,3 +1,4 @@ +// WITH_STDLIB // !DIAGNOSTICS: -UNUSED_VARIABLE class A @@ -17,4 +18,4 @@ inline fun bar() { val t3 = T?::class } -val m = Map::class +val m = Map::class diff --git a/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt b/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt index 50ed119efa9..717bf4a4fc9 100644 --- a/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt +++ b/compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt @@ -1,3 +1,4 @@ +// WITH_STDLIB // !DIAGNOSTICS: -UNUSED_VARIABLE class A diff --git a/compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.fir.kt new file mode 100644 index 00000000000..cfa4c0ba0d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.fir.kt @@ -0,0 +1,61 @@ +class Inv +class Some +class MyPair + +typealias InvAlias = Inv +typealias InvUnused = Inv +typealias SomeAlias = Some +typealias PairAliasSingle = MyPair +typealias PairAliasUsual = MyPair +typealias PairAliasReversed = MyPair +typealias PairAliasTwoWithUnused = MyPair +typealias PairAliasSpecific = MyPair +typealias SimpleArrayAlias = Array +typealias SpecificArrayAlias = Array +typealias UnusedArrayAlias = Array + +fun test() { + Inv::class + Inv::class + + InvAlias::class + InvAlias::class + + InvUnused::class + InvUnused::class + + Some::class + SomeAlias::class + SomeAlias::class + + MyPair::class + MyPair::class + + PairAliasSingle::class + PairAliasSingle::class + + PairAliasReversed::class + PairAliasReversed::class + + PairAliasUsual::class + PairAliasUsual::class + + PairAliasSpecific::class + + PairAliasTwoWithUnused::class + PairAliasTwoWithUnused::class + + Array::class + Array::class + Array<*>::class + + SimpleArrayAlias::class + SimpleArrayAlias::class + SimpleArrayAlias<*>::class + + SpecificArrayAlias::class + + UnusedArrayAlias::class + UnusedArrayAlias::class + UnusedArrayAlias<*>::class +} diff --git a/compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt b/compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt new file mode 100644 index 00000000000..04d954638e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt @@ -0,0 +1,61 @@ +class Inv +class Some +class MyPair + +typealias InvAlias = Inv +typealias InvUnused = Inv +typealias SomeAlias = Some +typealias PairAliasSingle = MyPair +typealias PairAliasUsual = MyPair +typealias PairAliasReversed = MyPair +typealias PairAliasTwoWithUnused = MyPair +typealias PairAliasSpecific = MyPair +typealias SimpleArrayAlias = Array +typealias SpecificArrayAlias = Array +typealias UnusedArrayAlias = Array + +fun test() { + Inv::class + Inv::class + + InvAlias::class + InvAlias::class + + InvUnused::class + InvUnused::class + + Some::class + SomeAlias::class + SomeAlias::class + + MyPair::class + MyPair::class + + PairAliasSingle::class + PairAliasSingle::class + + PairAliasReversed::class + PairAliasReversed::class + + PairAliasUsual::class + PairAliasUsual::class + + PairAliasSpecific::class + + PairAliasTwoWithUnused::class + PairAliasTwoWithUnused::class + + Array::class + Array::class + Array<*>::class + + SimpleArrayAlias::class + SimpleArrayAlias::class + SimpleArrayAlias<*>::class + + SpecificArrayAlias::class + + UnusedArrayAlias::class + UnusedArrayAlias::class + UnusedArrayAlias<*>::class +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 79913db4bf7..7fbcfef9576 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -3328,6 +3328,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/callableReference/genericCallWithReferenceAgainstVarargAndKFunction.kt"); } + @Test + @TestMetadata("genericTypealiasInLhs.kt") + public void testGenericTypealiasInLhs() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/genericTypealiasInLhs.kt"); + } + @Test @TestMetadata("kt15439_completeCall.kt") public void testKt15439_completeCall() throws Exception { @@ -4045,6 +4051,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/callableReference/generic/argumentExpectedType.kt"); } + @Test + @TestMetadata("boundViolated.kt") + public void testBoundViolated() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/boundViolated.kt"); + } + @Test @TestMetadata("dependOnArgumentType.kt") public void testDependOnArgumentType() throws Exception { @@ -4075,6 +4087,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/callableReference/generic/genericFunctionsWithNullableTypes.kt"); } + @Test + @TestMetadata("incorrectNumberOfTypeArguments.kt") + public void testIncorrectNumberOfTypeArguments() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/incorrectNumberOfTypeArguments.kt"); + } + @Test @TestMetadata("kt10968.kt") public void testKt10968() throws Exception { @@ -5380,6 +5398,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/classLiteral/nonClassesOnLHS.kt"); } + @Test + @TestMetadata("parameterizedTypeAlias.kt") + public void testParameterizedTypeAlias() throws Exception { + runTest("compiler/testData/diagnostics/tests/classLiteral/parameterizedTypeAlias.kt"); + } + @Test @TestMetadata("qualifiedClassLiteral.kt") public void testQualifiedClassLiteral() throws Exception {