diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonTypeCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonTypeCheckers.kt index 0a8e7083f93..febd3514269 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonTypeCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonTypeCheckers.kt @@ -21,5 +21,6 @@ object CommonTypeCheckers : TypeCheckers() { FirDuplicateParameterNameInFunctionTypeChecker, FirOptionalExpectationTypeChecker, FirIncompatibleClassTypeChecker, + FirContextReceiversTypeChecker, ) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirContextReceiversTypeChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirContextReceiversTypeChecker.kt new file mode 100644 index 00000000000..32f6a1270eb --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/type/FirContextReceiversTypeChecker.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2021 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.type + +import org.jetbrains.kotlin.KtFakeSourceElementKind +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.types.* + +object FirContextReceiversTypeChecker : FirTypeRefChecker() { + override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) { + if (context.languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) return + if (typeRef !is FirResolvedTypeRef) return + val source = typeRef.source ?: return + if (source.kind is KtFakeSourceElementKind) return + + if (typeRef.coneType.hasContextReceivers) { + reporter.reportOn( + source, + FirErrors.UNSUPPORTED_FEATURE, + LanguageFeature.ContextReceivers to context.languageVersionSettings, + context + ) + } + } +} + diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/unsupported.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/unsupported.fir.kt index 6dcf2eaa247..33c347b8f2e 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/unsupported.fir.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/unsupported.fir.kt @@ -1,8 +1,8 @@ // !DIAGNOSTICS: -UNCHECKED_CAST context(Any) -fun f(g: context(Any) () -> Unit, value: Any): context(A) () -> Unit { - return value as (context(A) () -> Unit) +fun f(g: context(Any) () -> Unit, value: Any): context(A) () -> Unit { + return value as (context(A) () -> Unit) } fun f(g: () -> Unit, value: Any) : () -> Unit {