Skip to content

Commit

Permalink
[FIR] Prepare FirFunctionParameterChecker to a future without context…
Browse files Browse the repository at this point in the history
… receivers
  • Loading branch information
cypressious authored and Space Team committed Feb 12, 2025
1 parent 4e14319 commit feeb3f8
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 11 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FILE: anonymousFunctionContextWithoutType.kt
public final fun foo(f: R|@ContextFunctionTypeParams (kotlin/String) -> kotlin/String|): R|kotlin/Unit| {
}
public final fun test(): R|kotlin/Unit| {
R|/foo<Inapplicable(INAPPLICABLE): /foo>#|(context(c@<ERROR TYPE REF: Symbol not found for c>) fun <anonymous>(): R|kotlin/Unit| <inline=Unknown> {
^@foo <Unresolved name: c>#
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN_PIPELINE_TILL: FRONTEND
// LANGUAGE: +ContextParameters

fun foo(f: context(String) () -> String) {}

fun test() {
// Should become green when context receivers are removed and we parse `c` as parameter without name instead of context receiver.
foo(<!ARGUMENT_TYPE_MISMATCH!>context(<!CONTEXT_PARAMETER_WITHOUT_NAME, UNRESOLVED_REFERENCE!>c<!>) fun() { return <!UNRESOLVED_REFERENCE!>c<!> }<!>)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,26 @@ object FirFunctionParameterChecker : FirFunctionChecker(MppCheckerKind.Common) {
private fun checkParameterTypes(function: FirFunction, context: CheckerContext, reporter: DiagnosticReporter) {
if (function is FirAnonymousFunction) return
for (valueParameter in function.valueParameters) {
val returnTypeRef = valueParameter.returnTypeRef
if (returnTypeRef !is FirErrorTypeRef) continue
// type problems on real source are already reported by ConeDiagnostic.toFirDiagnostics
if (returnTypeRef.source?.kind == KtRealSourceElementKind) continue
checkParameterType(valueParameter, reporter, context)
}
for (valueParameter in function.contextParameters) {
checkParameterType(valueParameter, reporter, context)
}
}

val diagnostic = returnTypeRef.diagnostic
if (diagnostic is ConeSimpleDiagnostic && diagnostic.kind == DiagnosticKind.ValueParameterWithNoTypeAnnotation) {
reporter.reportOn(
valueParameter.source, FirErrors.VALUE_PARAMETER_WITHOUT_EXPLICIT_TYPE,
context
)
}
private fun checkParameterType(
valueParameter: FirValueParameter,
reporter: DiagnosticReporter,
context: CheckerContext,
) {
val returnTypeRef = valueParameter.returnTypeRef
if (returnTypeRef !is FirErrorTypeRef) return
// type problems on real source are already reported by ConeDiagnostic.toFirDiagnostics
if (returnTypeRef.source?.kind == KtRealSourceElementKind) return

val diagnostic = returnTypeRef.diagnostic
if (diagnostic is ConeSimpleDiagnostic && diagnostic.kind == DiagnosticKind.ValueParameterWithNoTypeAnnotation) {
reporter.reportOn(valueParameter.source, FirErrors.VALUE_PARAMETER_WITHOUT_EXPLICIT_TYPE, context)
}
}

Expand Down

0 comments on commit feeb3f8

Please # to comment.