[FIR] Report UNSUPPORTED for default value in function type
This commit is contained in:
+5
@@ -163,4 +163,9 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
|||||||
get() = setOf(
|
get() = setOf(
|
||||||
FirEnumCompanionInEnumConstructorCallChecker,
|
FirEnumCompanionInEnumConstructorCallChecker,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val valueParameterCheckers: Set<FirValueParameterChecker>
|
||||||
|
get() = setOf(
|
||||||
|
FirUnsupportedDefaultValueInFunctionTypeChecker
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 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.declaration
|
||||||
|
|
||||||
|
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.declarations.FirValueParameter
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedDefaultValueInFunctionType
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
||||||
|
|
||||||
|
object FirUnsupportedDefaultValueInFunctionTypeChecker : FirValueParameterChecker() {
|
||||||
|
override fun check(declaration: FirValueParameter, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
|
val diagnostic = ((declaration.defaultValue?.typeRef as? FirErrorTypeRef)?.diagnostic as? ConeUnsupportedDefaultValueInFunctionType)
|
||||||
|
if (diagnostic != null) {
|
||||||
|
reporter.reportOn(diagnostic.source, FirErrors.UNSUPPORTED, diagnostic.reason, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -11,10 +11,14 @@ import org.jetbrains.kotlin.fakeElement
|
|||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
|
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||||
import org.jetbrains.kotlin.fir.resolve.SupertypeSupplier
|
import org.jetbrains.kotlin.fir.resolve.SupertypeSupplier
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedDefaultValueInFunctionType
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||||
import org.jetbrains.kotlin.fir.resolve.typeResolver
|
import org.jetbrains.kotlin.fir.resolve.typeResolver
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
||||||
@@ -180,4 +184,14 @@ class FirSpecificTypeResolverTransformer(
|
|||||||
override fun transformImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: ScopeClassDeclaration): FirTypeRef {
|
override fun transformImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: ScopeClassDeclaration): FirTypeRef {
|
||||||
return implicitTypeRef
|
return implicitTypeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun transformValueParameter(valueParameter: FirValueParameter, data: ScopeClassDeclaration): FirStatement {
|
||||||
|
val result = transformElement(valueParameter, data)
|
||||||
|
result.defaultValue?.let {
|
||||||
|
it.resultType = buildErrorTypeRef {
|
||||||
|
diagnostic = ConeUnsupportedDefaultValueInFunctionType(it.source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -204,6 +204,9 @@ class ConeImportFromSingleton(val name: Name) : ConeDiagnostic {
|
|||||||
|
|
||||||
open class ConeUnsupported(override val reason: String, val source: KtSourceElement? = null) : ConeDiagnostic
|
open class ConeUnsupported(override val reason: String, val source: KtSourceElement? = null) : ConeDiagnostic
|
||||||
|
|
||||||
|
open class ConeUnsupportedDefaultValueInFunctionType(source: KtSourceElement? = null) :
|
||||||
|
ConeUnsupported("Default value of parameter in function type", source)
|
||||||
|
|
||||||
class ConeUnresolvedParentInImport(val parentClassId: ClassId) : ConeDiagnostic {
|
class ConeUnresolvedParentInImport(val parentClassId: ClassId) : ConeDiagnostic {
|
||||||
override val reason: String
|
override val reason: String
|
||||||
get() = "unresolved import"
|
get() = "unresolved import"
|
||||||
|
|||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
|
||||||
|
|
||||||
fun f(x: Int = 0) {}
|
|
||||||
|
|
||||||
val inVal: (x: Int = 0)->Unit = {}
|
|
||||||
|
|
||||||
fun inParam(fn: (x: Int = 0)->Unit) {}
|
|
||||||
|
|
||||||
fun inParamNested(fn1: (fn2: (n: Int = 0)->Unit)->Unit) {}
|
|
||||||
|
|
||||||
fun inReturn(): (x: Int = 0)->Unit = {}
|
|
||||||
|
|
||||||
class A : (Int)->Unit {
|
|
||||||
override fun invoke(p1: Int) {
|
|
||||||
var lambda: (x: Int = 0)->Unit = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
val prop: (x: Int = 0)->Unit
|
|
||||||
get(): (x: Int = 0)->Unit = {}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
|
||||||
fun f(x: Int = 0) {}
|
fun f(x: Int = 0) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user