[FIR] Implement checker for value parameter default value type mismatch
#KT-58901 Fixed
This commit is contained in:
committed by
Space Team
parent
cfc824f9f2
commit
028921ade1
+3
-1
@@ -174,5 +174,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
||||
)
|
||||
|
||||
override val valueParameterCheckers: Set<FirValueParameterChecker>
|
||||
get() = setOf()
|
||||
get() = setOf(
|
||||
FirValueParameterDefaultValueTypeMismatchChecker,
|
||||
)
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.declaration
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.checkTypeMismatch
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
|
||||
object FirValueParameterDefaultValueTypeMismatchChecker : FirValueParameterChecker() {
|
||||
override fun check(declaration: FirValueParameter, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val defaultValue = declaration.defaultValue ?: return
|
||||
val source = requireNotNull(declaration.source)
|
||||
val parameterType = declaration.returnTypeRef.coneType
|
||||
|
||||
checkTypeMismatch(parameterType, null, defaultValue, context, source, reporter, true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user