K2: implement BUILDER_INFERENCE_STUB_RECEIVER

#KT-59369 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-11-28 23:30:11 +01:00
committed by Space Team
parent 5e5e5b8b9f
commit 0ed6256bcc
21 changed files with 162 additions and 70 deletions
@@ -4968,6 +4968,14 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token, token,
) )
} }
add(FirErrors.BUILDER_INFERENCE_STUB_RECEIVER) { firDiagnostic ->
BuilderInferenceStubReceiverImpl(
firDiagnostic.a,
firDiagnostic.b,
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirJvmErrors.OVERRIDE_CANNOT_BE_STATIC) { firDiagnostic -> add(FirJvmErrors.OVERRIDE_CANNOT_BE_STATIC) { firDiagnostic ->
OverrideCannotBeStaticImpl( OverrideCannotBeStaticImpl(
firDiagnostic as KtPsiDiagnostic, firDiagnostic as KtPsiDiagnostic,
@@ -3457,6 +3457,12 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
val presentableString: String val presentableString: String
} }
interface BuilderInferenceStubReceiver : KtFirDiagnostic<PsiElement> {
override val diagnosticClass get() = BuilderInferenceStubReceiver::class
val typeParameterName: Name
val containingDeclarationName: Name
}
interface OverrideCannotBeStatic : KtFirDiagnostic<PsiElement> { interface OverrideCannotBeStatic : KtFirDiagnostic<PsiElement> {
override val diagnosticClass get() = OverrideCannotBeStatic::class override val diagnosticClass get() = OverrideCannotBeStatic::class
} }
@@ -4169,6 +4169,13 @@ internal class IrWithUnstableAbiCompiledClassImpl(
token: KtLifetimeToken, token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.IrWithUnstableAbiCompiledClass ) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.IrWithUnstableAbiCompiledClass
internal class BuilderInferenceStubReceiverImpl(
override val typeParameterName: Name,
override val containingDeclarationName: Name,
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.BuilderInferenceStubReceiver
internal class OverrideCannotBeStaticImpl( internal class OverrideCannotBeStaticImpl(
firDiagnostic: KtPsiDiagnostic, firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken, token: KtLifetimeToken,
@@ -1764,6 +1764,13 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
parameter<String>("presentableString") parameter<String>("presentableString")
} }
} }
val BUILDER_INFERENCE by object : DiagnosticGroup("Builder inference") {
val BUILDER_INFERENCE_STUB_RECEIVER by error<PsiElement> {
parameter<Name>("typeParameterName")
parameter<Name>("containingDeclarationName")
}
}
} }
private val exposedVisibilityDiagnosticInit: DiagnosticBuilder.() -> Unit = { private val exposedVisibilityDiagnosticInit: DiagnosticBuilder.() -> Unit = {
@@ -869,6 +869,9 @@ object FirErrors {
val PRE_RELEASE_CLASS by error1<PsiElement, String>() val PRE_RELEASE_CLASS by error1<PsiElement, String>()
val IR_WITH_UNSTABLE_ABI_COMPILED_CLASS by error1<PsiElement, String>() val IR_WITH_UNSTABLE_ABI_COMPILED_CLASS by error1<PsiElement, String>()
// Builder inference
val BUILDER_INFERENCE_STUB_RECEIVER by error2<PsiElement, Name, Name>()
init { init {
RootDiagnosticRendererFactory.registerFactory(FirErrorsDefaultMessages) RootDiagnosticRendererFactory.registerFactory(FirErrorsDefaultMessages)
} }
@@ -571,6 +571,7 @@ val FIR_NON_SUPPRESSIBLE_ERROR_NAMES: Set<String> = setOf(
"INCOMPATIBLE_CLASS", "INCOMPATIBLE_CLASS",
"PRE_RELEASE_CLASS", "PRE_RELEASE_CLASS",
"IR_WITH_UNSTABLE_ABI_COMPILED_CLASS", "IR_WITH_UNSTABLE_ABI_COMPILED_CLASS",
"BUILDER_INFERENCE_STUB_RECEIVER",
"OVERRIDE_CANNOT_BE_STATIC", "OVERRIDE_CANNOT_BE_STATIC",
"JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION", "JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION",
"JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION", "JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION",
@@ -112,6 +112,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BOUNDS_NOT_ALLOWE
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BOUND_ON_TYPE_ALIAS_PARAMETER_NOT_ALLOWED import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BOUND_ON_TYPE_ALIAS_PARAMETER_NOT_ALLOWED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BUILDER_INFERENCE_STUB_RECEIVER
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CALLABLE_REFERENCE_LHS_NOT_A_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CALLABLE_REFERENCE_LHS_NOT_A_CLASS
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CANNOT_ALL_UNDER_IMPORT_FROM_SINGLETON import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CANNOT_ALL_UNDER_IMPORT_FROM_SINGLETON
@@ -2570,5 +2571,12 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
"{0} is compiled by an unstable version of the Kotlin compiler and cannot be loaded by this compiler.", "{0} is compiled by an unstable version of the Kotlin compiler and cannot be loaded by this compiler.",
STRING STRING
) )
map.put(
BUILDER_INFERENCE_STUB_RECEIVER,
"The type of a receiver hasn''t been inferred yet. Please specify type argument for generic parameter `{0}` of `{1}` explicitly",
TO_STRING,
TO_STRING
);
} }
} }
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isLocalMember import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isLocalMember
import org.jetbrains.kotlin.fir.analysis.getChild import org.jetbrains.kotlin.fir.analysis.getChild
import org.jetbrains.kotlin.fir.builder.FirSyntaxErrors import org.jetbrains.kotlin.fir.builder.FirSyntaxErrors
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.diagnostics.* import org.jetbrains.kotlin.fir.diagnostics.*
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExpectedTypeConstrai
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
@@ -307,6 +309,16 @@ private fun mapInapplicableCandidateError(
rootCause.expectedContextReceiverType.removeTypeVariableTypes(typeContext) rootCause.expectedContextReceiverType.removeTypeVariableTypes(typeContext)
) )
is StubBuilderInferenceReceiver -> {
val typeParameterSymbol = rootCause.typeParameterSymbol
@OptIn(SymbolInternals::class)
FirErrors.BUILDER_INFERENCE_STUB_RECEIVER.createOn(
qualifiedAccessSource ?: source,
typeParameterSymbol.name,
(typeParameterSymbol.containingDeclarationSymbol.fir as FirMemberDeclaration).nameOrSpecialName
)
}
is NullForNotNullType -> FirErrors.NULL_FOR_NONNULL_TYPE.createOn( is NullForNotNullType -> FirErrors.NULL_FOR_NONNULL_TYPE.createOn(
rootCause.argument.source ?: source, rootCause.expectedType.removeTypeVariableTypes(typeContext) rootCause.argument.source ?: source, rootCause.expectedType.removeTypeVariableTypes(typeContext)
) )
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope
import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.fir.scopes.impl.typeAliasForConstructor import org.jetbrains.kotlin.fir.scopes.impl.typeAliasForConstructor
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.symbols.impl.*
@@ -129,6 +130,21 @@ object CheckExtensionReceiver : ResolutionStage() {
candidate.chosenExtensionReceiver = receiver.expression candidate.chosenExtensionReceiver = receiver.expression
val checkBuilderInferenceRestriction =
!context.session.languageVersionSettings
.supportsFeature(LanguageFeature.NoBuilderInferenceWithoutAnnotationRestriction)
if (checkBuilderInferenceRestriction) {
val resolvedType = receiver.expression.resolvedType
if (resolvedType is ConeStubTypeForChainInference) {
val typeVariable = resolvedType.constructor.variable
sink.yieldDiagnostic(
StubBuilderInferenceReceiver(
(typeVariable.typeConstructor.originalTypeParameter as ConeTypeParameterLookupTag).typeParameterSymbol
)
)
}
}
sink.yieldIfNeed() sink.yieldIfNeed()
} }
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirReceiverParameter
import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression
@@ -14,6 +15,7 @@ import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeTypeVariable import org.jetbrains.kotlin.fir.types.ConeTypeVariable
import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget
@@ -153,3 +155,7 @@ object ResolutionResultOverridesOtherToPreserveCompatibility : ResolutionDiagnos
object AdaptedCallableReferenceIsUsedWithReflection : ResolutionDiagnostic(RESOLVED_WITH_ERROR) object AdaptedCallableReferenceIsUsedWithReflection : ResolutionDiagnostic(RESOLVED_WITH_ERROR)
object TypeParameterAsExpression : ResolutionDiagnostic(INAPPLICABLE) object TypeParameterAsExpression : ResolutionDiagnostic(INAPPLICABLE)
class StubBuilderInferenceReceiver(
val typeParameterSymbol: FirTypeParameterSymbol
) : ResolutionDiagnostic(RESOLVED_WITH_ERROR)
@@ -12,7 +12,7 @@ fun main() {
buildList { buildList {
add(Bar()) add(Bar())
this.get(0).test() // resolved to Any?.test <!BUILDER_INFERENCE_STUB_RECEIVER!>this.get(0).test()<!> // resolved to Any?.test
} }
buildList<Bar> { buildList<Bar> {
add(Bar()) add(Bar())
@@ -13,7 +13,7 @@ FILE: errorOnStubReceiver.fir.kt
public final fun main(): R|kotlin/Unit| { public final fun main(): R|kotlin/Unit| {
R|kotlin/collections/buildList|<R|Bar|>(<L> = buildList@fun R|kotlin/collections/MutableList<Bar>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> { R|kotlin/collections/buildList|<R|Bar|>(<L> = buildList@fun R|kotlin/collections/MutableList<Bar>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(R|/Bar.Bar|()) this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(R|/Bar.Bar|())
this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.get: R|Stub (chain inference): TypeVariable(E)|>|(Int(0)).R|/test|() this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.get: R|Stub (chain inference): TypeVariable(E)|>|(Int(0)).R|/test<Inapplicable(RESOLVED_WITH_ERROR): /test>#|()
} }
) )
R|kotlin/collections/buildList|<R|Bar|>(<L> = buildList@fun R|kotlin/collections/MutableList<Bar>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> { R|kotlin/collections/buildList|<R|Bar|>(<L> = buildList@fun R|kotlin/collections/MutableList<Bar>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
@@ -76,13 +76,13 @@ fun main() {
val list6 = buildList { val list6 = buildList {
add("one") add("one")
get(0).<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>() get(0).<!NONE_APPLICABLE!>bar<!>()
} }
val list7 = buildList { val list7 = buildList {
add("one") add("one")
with (get(0)) { with (get(0)) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>() <!NONE_APPLICABLE!>bar<!>()
} }
} }
val list71 = buildList { val list71 = buildList {
@@ -90,7 +90,7 @@ fun main() {
with (get(0)) l1@ { with (get(0)) l1@ {
with (listOf(1)) { with (listOf(1)) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>() <!NONE_APPLICABLE!>bar<!>()
} }
} }
} }
@@ -99,7 +99,7 @@ fun main() {
with (get(0)) { with (get(0)) {
with (listOf(1)) { with (listOf(1)) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>() <!NONE_APPLICABLE!>bar<!>()
} }
} }
} }
@@ -122,7 +122,7 @@ fun main() {
with (get(0)) { with (get(0)) {
with (Inv(this)) { with (Inv(this)) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>() <!NONE_APPLICABLE!>bar<!>()
} }
} }
} }
@@ -161,14 +161,14 @@ fun main() {
add("one") add("one")
with (get(0)) { with (get(0)) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo0003<!>(0f, this@l1.get(0)) <!NONE_APPLICABLE!>foo0003<!>(0f, this@l1.get(0))
} }
} }
val list18 = buildList { val list18 = buildList {
add("one") add("one")
get(0).<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo0003<!>(0f, get(0)) get(0).<!NONE_APPLICABLE!>foo0003<!>(0f, get(0))
} }
val map1 = buildMap { val map1 = buildMap {
@@ -211,7 +211,7 @@ fun test() {
add("") add("")
with (get()) { with (get()) {
with (listOf(1)) { with (listOf(1)) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>bar<!>() <!NONE_APPLICABLE!>bar<!>()
} }
} }
}, },
@@ -3,7 +3,7 @@
fun test() { fun test() {
foo( foo(
flow { emit(0) } flow { emit(0) }
) { it.collect <!TOO_MANY_ARGUMENTS!>{}<!> } ) { <!BUILDER_INFERENCE_STUB_RECEIVER!>it.collect <!TOO_MANY_ARGUMENTS!>{}<!><!> }
// 0. Initial // 0. Initial
// W <: Any / declared upper bound // W <: Any / declared upper bound
@@ -20,37 +20,37 @@ fun test() {
val ret1 = build { val ret1 = build {
emit(1) emit(1)
emit(null) emit(null)
get()?.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test()<!>
get()?.test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test2()<!>
get().test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get().test2()<!>
get()?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.hashCode()<!>
get()?.<!NONE_APPLICABLE!>equals<!>(1) get()?.<!NONE_APPLICABLE!>equals<!>(1)
// there is `String?.equals` extension // there is `String?.equals` extension
get().equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>get().equals("")<!>
} }
val ret2 = build { val ret2 = build {
emit(1) emit(1)
emit(null) emit(null)
get()?.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test()<!>
get()?.test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test2()<!>
get().test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get().test2()<!>
get()?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.hashCode()<!>
get()?.<!NONE_APPLICABLE!>equals<!>(1) get()?.<!NONE_APPLICABLE!>equals<!>(1)
val x = get() val x = get()
x?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>x?.hashCode()<!>
x?.<!NONE_APPLICABLE!>equals<!>(1) x?.<!NONE_APPLICABLE!>equals<!>(1)
x.equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>x.equals("")<!>
} }
val ret3 = build { val ret3 = build {
emit(1) emit(1)
emit(null) emit(null)
get()?.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test()<!>
get()?.test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test2()<!>
get().test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get().test2()<!>
get()?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.hashCode()<!>
get()?.<!NONE_APPLICABLE!>equals<!>(1) get()?.<!NONE_APPLICABLE!>equals<!>(1)
val x = get() val x = get()
x?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>x?.hashCode()<!>
x?.<!NONE_APPLICABLE!>equals<!>(1) x?.<!NONE_APPLICABLE!>equals<!>(1)
if (get() == null) {} if (get() == null) {}
@@ -153,20 +153,20 @@ fun test() {
emit(1) emit(1)
emit(null) emit(null)
val x = get() val x = get()
x.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>x.test()<!>
"" ""
} }
val ret41 = build { val ret41 = build {
emit(1) emit(1)
emit(null) emit(null)
get()?.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test()<!>
get()?.test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test2()<!>
get().test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get().test2()<!>
get()?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.hashCode()<!>
get()?.<!NONE_APPLICABLE!>equals<!>(1) get()?.<!NONE_APPLICABLE!>equals<!>(1)
val x = get() val x = get()
x?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>x?.hashCode()<!>
x?.<!NONE_APPLICABLE!>equals<!>(1) x?.<!NONE_APPLICABLE!>equals<!>(1)
if (get() == null) {} if (get() == null) {}
@@ -284,19 +284,19 @@ fun test() {
emit(1) emit(1)
emit(null) emit(null)
val x = get() val x = get()
x.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>x.test()<!>
"" ""
} }
val ret51 = build { val ret51 = build {
emit(1) emit(1)
emit(null) emit(null)
get()?.test() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test()<!>
get()?.test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.test2()<!>
get().test2() <!BUILDER_INFERENCE_STUB_RECEIVER!>get().test2()<!>
get()?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>get()?.hashCode()<!>
get()?.<!NONE_APPLICABLE!>equals<!>(1) get()?.<!NONE_APPLICABLE!>equals<!>(1)
val x = get() val x = get()
x?.hashCode() <!BUILDER_INFERENCE_STUB_RECEIVER!>x?.hashCode()<!>
x?.<!NONE_APPLICABLE!>equals<!>(1) x?.<!NONE_APPLICABLE!>equals<!>(1)
if (get() == null) {} if (get() == null) {}
@@ -25,27 +25,27 @@ fun <R1 : R2, R2> build4(x: R2, block: TestInterface<R1>.() -> Unit): R1 = TODO(
fun test(a: String?) { fun test(a: String?) {
val ret1 = build { val ret1 = build {
emit(1) emit(1)
get()<!UNNECESSARY_SAFE_CALL!>?.<!>equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>get()<!UNNECESSARY_SAFE_CALL!>?.<!>equals("")<!>
val x = get() val x = get()
x<!UNNECESSARY_SAFE_CALL!>?.<!>equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>x<!UNNECESSARY_SAFE_CALL!>?.<!>equals("")<!>
x <!USELESS_ELVIS!>?: 1<!> x <!USELESS_ELVIS!>?: 1<!>
x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
"" ""
} }
val ret2 = build2 { val ret2 = build2 {
emit(1) emit(1)
get()<!UNNECESSARY_SAFE_CALL!>?.<!>equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>get()<!UNNECESSARY_SAFE_CALL!>?.<!>equals("")<!>
val x = get() val x = get()
x<!UNNECESSARY_SAFE_CALL!>?.<!>equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>x<!UNNECESSARY_SAFE_CALL!>?.<!>equals("")<!>
x <!USELESS_ELVIS!>?: 1<!> x <!USELESS_ELVIS!>?: 1<!>
x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
"" ""
} }
val ret3 = build3 { val ret3 = build3 {
emit(1) emit(1)
get()<!UNNECESSARY_SAFE_CALL!>?.<!>equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>get()<!UNNECESSARY_SAFE_CALL!>?.<!>equals("")<!>
val x = get() val x = get()
x<!UNNECESSARY_SAFE_CALL!>?.<!>equals("") <!BUILDER_INFERENCE_STUB_RECEIVER!>x<!UNNECESSARY_SAFE_CALL!>?.<!>equals("")<!>
x <!USELESS_ELVIS!>?: 1<!> x <!USELESS_ELVIS!>?: 1<!>
x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
"" ""
@@ -9,9 +9,9 @@ fun use(p: Any?) {}
fun test1() { fun test1() {
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> { <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> {
this.get(0).extension() <!BUILDER_INFERENCE_STUB_RECEIVER!>this.get(0).extension()<!>
use(this.get(0)::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>this.get(0)::extension<!>)
use(it::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>it::extension<!>)
} }
} }
@@ -19,9 +19,9 @@ fun test1() {
fun test2() { fun test2() {
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> { <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> {
val v = this.get(0) val v = this.get(0)
v.extension() <!BUILDER_INFERENCE_STUB_RECEIVER!>v.extension()<!>
use(v::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>v::extension<!>)
use(it::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>it::extension<!>)
} }
} }
@@ -29,9 +29,9 @@ fun test3() {
operator fun <T> T.getValue(thisRef: Any?, prop: Any?): T = this operator fun <T> T.getValue(thisRef: Any?, prop: Any?): T = this
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> { <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> {
val v by this.get(0) val v by this.get(0)
v.extension() <!BUILDER_INFERENCE_STUB_RECEIVER!>v.extension()<!>
use(v::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>v::extension<!>)
use(it::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>it::extension<!>)
} }
} }
@@ -42,9 +42,9 @@ fun test4() {
operator fun <T> Box<T>.getValue(thisRef: Any?, prop: Any?): T = this.t operator fun <T> Box<T>.getValue(thisRef: Any?, prop: Any?): T = this.t
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> { <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>a<!> {
val v by this.get(0) val v by this.get(0)
v.extension() v.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>extension<!>()
use(v::extension) use(v::extension)
use(it::extension) use(<!BUILDER_INFERENCE_STUB_RECEIVER!>it::extension<!>)
} }
} }
@@ -53,20 +53,20 @@ fun <R> b(lambda: R.(List<R>) -> Unit) {}
fun test5() { fun test5() {
operator fun <T> T.invoke(): T = this operator fun <T> T.invoke(): T = this
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>b<!> { b {
extension() <!BUILDER_INFERENCE_STUB_RECEIVER!>extension()<!>
this().extension() <!BUILDER_INFERENCE_STUB_RECEIVER!><!BUILDER_INFERENCE_STUB_RECEIVER!>this()<!>.extension()<!>
use(::extension) <!BUILDER_INFERENCE_STUB_RECEIVER!>use(<!BUILDER_INFERENCE_STUB_RECEIVER!>::extension<!>)<!>
} }
} }
val <T> T.genericLambda: T.((T) -> Unit) -> Unit get() = {} val <T> T.genericLambda: T.((T) -> Unit) -> Unit get() = {}
fun test6() { fun test6() {
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>b<!> { b {
extension() <!BUILDER_INFERENCE_STUB_RECEIVER!>extension()<!>
genericLambda { } <!BUILDER_INFERENCE_STUB_RECEIVER!>genericLambda { }<!>
genericLambda { it.extension() } <!BUILDER_INFERENCE_STUB_RECEIVER!>genericLambda { it.extension() }<!>
use(::extension) <!BUILDER_INFERENCE_STUB_RECEIVER!>use(<!BUILDER_INFERENCE_STUB_RECEIVER!>::extension<!>)<!>
} }
} }
@@ -10,7 +10,7 @@ fun main(arg: Any) {
val value = myBuilder { val value = myBuilder {
doSmthng("one ") doSmthng("one ")
run { a; this }.a = 10 run { a; this }.a = 10
a += 1 <!BUILDER_INFERENCE_STUB_RECEIVER!>a += 1<!>
this.a = 57 this.a = 57
this.<!ILLEGAL_SELECTOR, VARIABLE_EXPECTED!>(a)<!> = 57 this.<!ILLEGAL_SELECTOR, VARIABLE_EXPECTED!>(a)<!> = 57
a = x a = x
@@ -26,18 +26,18 @@ fun main(arg: Any, condition: Boolean) {
val value = myBuilder { val value = myBuilder {
b[0] = 123 b[0] = 123
a = 45 a = 45
a<!OVERLOAD_RESOLUTION_AMBIGUITY!>++<!> a<!NONE_APPLICABLE!>++<!>
bar(::a) bar(::a)
if (<!USELESS_IS_CHECK!>a is Int<!>) { if (<!USELESS_IS_CHECK!>a is Int<!>) {
a = 67 a = 67
a<!OVERLOAD_RESOLUTION_AMBIGUITY!>--<!> a<!NONE_APPLICABLE!>--<!>
bar(::a) bar(::a)
} }
when (condition) { when (condition) {
true -> a = 87 true -> a = 87
false -> a = 65 false -> a = 65
} }
val x by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY!>a<!> val x by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>a<!>
change { change {
a = 99 a = 99
@@ -0,0 +1,19 @@
// !OPT_IN: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.experimental.ExperimentalTypeInference
class TypeDefinition<KotlinType : Any> {
fun parse(parser: (serializedValue: String) -> KotlinType?): Unit = TODO()
fun serialize(parser: (value: KotlinType) -> Any?): Unit = TODO()
}
@OptIn(ExperimentalTypeInference::class)
fun <KotlinType : Any> defineType(definition: TypeDefinition<KotlinType>.() -> Unit): Unit = TODO()
fun main() {
defineType {
parse { it.toInt() }
serialize { <!BUILDER_INFERENCE_STUB_RECEIVER!>it.toString()<!> }
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !OPT_IN: kotlin.RequiresOptIn // !OPT_IN: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER