[FIR] Fix inconsistent RETURN_TYPE_MISMATCH and TYPE_MISMATCH reporting on functions and properties
^KT-51203 Fixed
This commit is contained in:
+2
-2
@@ -302,10 +302,10 @@ private object FirToKtConversionCreator {
|
||||
KtSymbol::class.createType(),
|
||||
importsToAdd = listOf("org.jetbrains.kotlin.fir.declarations.FirDeclaration")
|
||||
),
|
||||
FirSimpleFunction::class to HLFunctionCallConversion(
|
||||
FirFunction::class to HLFunctionCallConversion(
|
||||
"firSymbolBuilder.buildSymbol({0})",
|
||||
KtSymbol::class.createType(),
|
||||
importsToAdd = listOf("org.jetbrains.kotlin.fir.declarations.FirSimpleFunction")
|
||||
importsToAdd = listOf("org.jetbrains.kotlin.fir.declarations.FirFunction")
|
||||
),
|
||||
FirNamedFunctionSymbol::class to HLFunctionCallConversion(
|
||||
"firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol({0})",
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.builder.FirSyntaxErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ open class J() : S() {
|
||||
}
|
||||
|
||||
open class Base<T : X, Z : T> {
|
||||
open fun kek(): Z = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>Z()<!>
|
||||
open fun kek(): Z = <!RETURN_TYPE_MISMATCH!>Z()<!>
|
||||
}
|
||||
|
||||
open class GoodDerrived : Base<Y, W>() {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ class C
|
||||
class B
|
||||
|
||||
class A {
|
||||
val B.foo: C.() -> Unit get() = null
|
||||
val B.foo: C.() -> Unit get() = <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
}
|
||||
|
||||
fun <T, R> with(arg: T, f: T.() -> R): R = arg.f()
|
||||
|
||||
Vendored
+1
-1
@@ -81,7 +81,7 @@ open class J {
|
||||
}
|
||||
|
||||
var bar = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>
|
||||
get() = 3.1415926535
|
||||
get() = <!RETURN_TYPE_MISMATCH!>3.1415926535<!>
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ fun ok(): Int {
|
||||
}
|
||||
|
||||
fun okOneLineFunction(): Int = 10 + 1
|
||||
fun errorOneLineFunction(): String = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>10 + 1<!>
|
||||
fun errorOneLineFunction(): String = <!RETURN_TYPE_MISMATCH!>10 + 1<!>
|
||||
|
||||
class A {
|
||||
fun bar() {}
|
||||
@@ -37,7 +37,7 @@ fun errorWithLambda(): String {
|
||||
return@foo
|
||||
} foo {
|
||||
bar()
|
||||
return@foo 10
|
||||
return@foo <!RETURN_TYPE_MISMATCH!>10<!>
|
||||
}
|
||||
|
||||
return ""
|
||||
|
||||
+2
-2
@@ -8,5 +8,5 @@ abstract class LightMemberImpl<out D : PsiMember>(computeRealDelegate: () -> D)
|
||||
|
||||
abstract class LightFieldImpl<D : PsiField>(computeRealDelegate: () -> D) : LightMemberImpl<PsiField>(computeRealDelegate) {
|
||||
override val delegate: D
|
||||
get() = super.delegate
|
||||
}
|
||||
get() = <!RETURN_TYPE_MISMATCH!>super.delegate<!>
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
@@ -624,7 +624,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
val RETURN_TYPE_MISMATCH by error<KtExpression>(PositioningStrategy.WHOLE_ELEMENT) {
|
||||
parameter<ConeKotlinType>("expectedType")
|
||||
parameter<ConeKotlinType>("actualType")
|
||||
parameter<FirSimpleFunction>("targetFunction")
|
||||
parameter<FirFunction>("targetFunction")
|
||||
parameter<Boolean>("isMismatchDueToNullability")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
|
||||
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
|
||||
@@ -393,7 +393,7 @@ object FirErrors {
|
||||
val REIFIED_TYPE_PARAMETER_NO_INLINE by error0<KtTypeParameter>(SourceElementPositioningStrategies.REIFIED_MODIFIER)
|
||||
val TYPE_PARAMETERS_NOT_ALLOWED by error0<KtDeclaration>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
|
||||
val TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER by error0<KtTypeParameter>()
|
||||
val RETURN_TYPE_MISMATCH by error4<KtExpression, ConeKotlinType, ConeKotlinType, FirSimpleFunction, Boolean>(SourceElementPositioningStrategies.WHOLE_ELEMENT)
|
||||
val RETURN_TYPE_MISMATCH by error4<KtExpression, ConeKotlinType, ConeKotlinType, FirFunction, Boolean>(SourceElementPositioningStrategies.WHOLE_ELEMENT)
|
||||
val CYCLIC_GENERIC_UPPER_BOUND by error0<PsiElement>()
|
||||
val DEPRECATED_TYPE_PARAMETER_SYNTAX by error0<KtDeclaration>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
|
||||
val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning0<KtTypeParameter>()
|
||||
|
||||
+14
-5
@@ -5,14 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
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.checkers.isSubtypeForTypeMismatch
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NULL_FOR_NONNULL_TYPE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_TYPE_MISMATCH
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SMARTCAST_IMPOSSIBLE
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirErrorFunction
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
|
||||
import org.jetbrains.kotlin.fir.expressions.FirReturnExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirWhenExpression
|
||||
@@ -23,12 +25,19 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
||||
override fun check(expression: FirReturnExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (expression.source == null) return
|
||||
val targetElement = expression.target.labeledElement
|
||||
if (targetElement !is FirSimpleFunction) return
|
||||
if (targetElement is FirErrorFunction ||
|
||||
targetElement is FirAnonymousFunction && targetElement.isLambda && expression.target.labelName == null
|
||||
) {
|
||||
return
|
||||
}
|
||||
val resultExpression = expression.result
|
||||
// To avoid duplications with NO_ELSE_IN_WHEN or INVALID_IF_AS_EXPRESSION
|
||||
if (resultExpression is FirWhenExpression && !resultExpression.isExhaustive) return
|
||||
|
||||
val functionReturnType = targetElement.returnTypeRef.coneType
|
||||
val functionReturnType = if (targetElement is FirConstructor)
|
||||
context.session.builtinTypes.unitType.coneType
|
||||
else
|
||||
targetElement.returnTypeRef.coneType
|
||||
val typeContext = context.session.typeContext
|
||||
val returnExpressionType = resultExpression.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
||||
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran
|
||||
ResolutionMode.ContextDependent
|
||||
}
|
||||
else -> {
|
||||
ResolutionMode.WithExpectedType(expectedTypeRef)
|
||||
ResolutionMode.WithExpectedType(expectedTypeRef, expectedTypeMismatchIsReportedInChecker = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -15,4 +15,4 @@ public interface J2 {
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun baz(j2: J2): Any = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>j2.bar().foo()<!> // Any..Any?
|
||||
fun baz(j2: J2): Any = <!RETURN_TYPE_MISMATCH!>j2.bar().foo()<!> // Any..Any?
|
||||
|
||||
compiler/testData/diagnostics/tests/callableReference/unitAdaptationForReferenceCompatibility.fir.kt
Vendored
+1
-1
@@ -21,5 +21,5 @@ fun f(): String = "test"
|
||||
|
||||
class A {
|
||||
fun schedule1(e: Executor): Future<String> = e.submit(::f)
|
||||
fun schedule2(e: Executor): Future<String> = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>e.submit { f() }<!>
|
||||
fun schedule2(e: Executor): Future<String> = <!RETURN_TYPE_MISMATCH!>e.submit { f() }<!>
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ operator fun Impl2.unaryMinus() = Impl2()
|
||||
// See also KT-10384: in non-error functions, as is necessary!
|
||||
fun add1(x: Impl2, y: Base): Impl1 = x as Base + y
|
||||
|
||||
fun error1(x: Impl2, y: Base): Impl1 = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>x + y<!>
|
||||
fun error1(x: Impl2, y: Base): Impl1 = <!RETURN_TYPE_MISMATCH!>x + y<!>
|
||||
|
||||
fun add2(x: Base, y: Impl2): Impl1 = x + y as Base
|
||||
|
||||
fun error2(x: Base, y: Impl2): Impl1 = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>x + y<!>
|
||||
fun error2(x: Base, y: Impl2): Impl1 = <!RETURN_TYPE_MISMATCH!>x + y<!>
|
||||
|
||||
fun minus3(x: Impl2): Impl1 = -(x as Base)
|
||||
|
||||
fun error3(x: Impl2): Impl1 = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>-x<!>
|
||||
fun error3(x: Impl2): Impl1 = <!RETURN_TYPE_MISMATCH!>-x<!>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ fun testResultOfAnonFun2() =
|
||||
|
||||
fun testReturnFromAnonFun() =
|
||||
run(fun () {
|
||||
return if (true) 42 else println()
|
||||
return <!RETURN_TYPE_MISMATCH!>if (true) 42 else println()<!>
|
||||
})
|
||||
|
||||
fun testReturn1() =
|
||||
|
||||
@@ -37,9 +37,9 @@ fun test4() = run {
|
||||
|
||||
val foo: Int
|
||||
get() = run {
|
||||
if (true) return ""
|
||||
if (true) return <!RETURN_TYPE_MISMATCH!>""<!>
|
||||
|
||||
return
|
||||
<!RETURN_TYPE_MISMATCH!>return<!>
|
||||
}
|
||||
|
||||
fun test(): Int = run {
|
||||
|
||||
+8
-8
@@ -3,16 +3,16 @@
|
||||
|
||||
fun test1(): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
fun test2(): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
val test3: () -> Int = fun (): Int = { <!RETURN_NOT_ALLOWED!>return<!> 1 }
|
||||
val test4: () -> Int = fun (): Int = { 1 }
|
||||
val test3: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
val test4: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
fun test5(): Int { return <!RETURN_TYPE_MISMATCH!>{ 1 }<!> }
|
||||
fun test6(): Int = <!RETURN_TYPE_MISMATCH!>fun (): Int = 1<!>
|
||||
|
||||
fun outer() {
|
||||
fun test1(): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
fun test2(): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
val test3: () -> Int = fun (): Int = { <!RETURN_NOT_ALLOWED!>return<!> 1 }
|
||||
val test4: () -> Int = fun (): Int = { 1 }
|
||||
val test3: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
val test4: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
fun test5(): Int { return <!RETURN_TYPE_MISMATCH!>{ 1 }<!> }
|
||||
fun test6(): Int = <!RETURN_TYPE_MISMATCH!>fun (): Int = 1<!>
|
||||
}
|
||||
@@ -20,16 +20,16 @@ fun outer() {
|
||||
class Outer {
|
||||
fun test1(): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
fun test2(): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
val test3: () -> Int = fun (): Int = { <!RETURN_NOT_ALLOWED!>return<!> 1 }
|
||||
val test4: () -> Int = fun (): Int = { 1 }
|
||||
val test3: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
val test4: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
fun test5(): Int { return <!RETURN_TYPE_MISMATCH!>{ 1 }<!> }
|
||||
fun test6(): Int = <!RETURN_TYPE_MISMATCH!>fun (): Int = 1<!>
|
||||
|
||||
class Nested {
|
||||
fun test1(): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
fun test2(): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
val test3: () -> Int = fun (): Int = { <!RETURN_NOT_ALLOWED!>return<!> 1 }
|
||||
val test4: () -> Int = fun (): Int = { 1 }
|
||||
val test3: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ <!RETURN_NOT_ALLOWED!>return<!> 1 }<!>
|
||||
val test4: () -> Int = fun (): Int = <!RETURN_TYPE_MISMATCH!>{ 1 }<!>
|
||||
fun test5(): Int { return <!RETURN_TYPE_MISMATCH!>{ 1 }<!> }
|
||||
fun test6(): Int = <!RETURN_TYPE_MISMATCH!>fun (): Int = 1<!>
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -24,4 +24,4 @@ class C<R>() {
|
||||
}
|
||||
|
||||
var c1: Int by C()
|
||||
var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>C<Number>()<!>
|
||||
var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>C<Number>()<!>
|
||||
|
||||
+1
-1
@@ -12,5 +12,5 @@ fun String.provideDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this)
|
||||
operator fun String.getValue(a: Any?, p: KProperty<*>) = this
|
||||
|
||||
val test1: String by "OK"
|
||||
val test2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>"OK"<!>
|
||||
val test2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>"OK"<!>
|
||||
val test3 by "OK"
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val c: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>Delegate()<!>
|
||||
val c: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>Delegate()<!>
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): String {
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@ val foo = fun(a: Int): String {
|
||||
if (a == 1) return "4"
|
||||
when (a) {
|
||||
5 -> return "2"
|
||||
3 -> return null
|
||||
2 -> return 2
|
||||
3 -> return <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
2 -> return <!RETURN_TYPE_MISMATCH!>2<!>
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ fun main() {
|
||||
|
||||
val a0: () -> Int = <!INITIALIZER_TYPE_MISMATCH!>fun(): String = "1"<!>
|
||||
val a1: () -> Int = <!INITIALIZER_TYPE_MISMATCH!>(fun() = "1")<!>
|
||||
val a2: () -> Unit = (fun() = "1")
|
||||
val a3: Unit = <!INITIALIZER_TYPE_MISMATCH!>(fun() = "1")<!>
|
||||
val a2: () -> Unit = (fun() = <!RETURN_TYPE_MISMATCH!>"1"<!>)
|
||||
val a3: Unit = <!INITIALIZER_TYPE_MISMATCH!>(fun() = <!RETURN_TYPE_MISMATCH!>"1"<!>)<!>
|
||||
val a4 = (fun() = "1")
|
||||
val a5 = (fun(): String = "1")
|
||||
val a6: () -> Int = (fun() = 1)
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ val a: () -> Int = <!INITIALIZER_TYPE_MISMATCH!>l@ {
|
||||
}<!>
|
||||
|
||||
val b: () -> Unit = l@ {
|
||||
if (flag) return@l 4
|
||||
if (flag) return@l <!RETURN_TYPE_MISMATCH!>4<!>
|
||||
}
|
||||
|
||||
val c: () -> Any = l@ {
|
||||
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
val flag = true
|
||||
|
||||
val a = b@ {
|
||||
if (flag) return@b 4
|
||||
return@b
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
val flag = true
|
||||
|
||||
val a = b@ {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun test(a: Int) {
|
||||
run<Int>f@{
|
||||
if (a > 0) return@f <!ARGUMENT_TYPE_MISMATCH!>""<!>
|
||||
if (a > 0) return@f <!ARGUMENT_TYPE_MISMATCH, RETURN_TYPE_MISMATCH!>""<!>
|
||||
return@f 1
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ fun test(a: A<out CharSequence>, z: Out<CharSequence>) {
|
||||
a.bar { <!ARGUMENT_TYPE_MISMATCH, TYPE_MISMATCH!>z.id()<!> }
|
||||
|
||||
a.foo {
|
||||
z.foobar(if (1 > 2) return@foo <!ARGUMENT_TYPE_MISMATCH!>""<!> else "")
|
||||
z.foobar(if (1 > 2) return@foo <!ARGUMENT_TYPE_MISMATCH, RETURN_TYPE_MISMATCH!>""<!> else "")
|
||||
<!ARGUMENT_TYPE_MISMATCH!>""<!>
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ fun foo(): String? {
|
||||
run {
|
||||
if (true) return@run
|
||||
|
||||
if (true) return <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>Obj()<!> // correct error, type check against return type of function "foo"
|
||||
if (true) return <!RETURN_TYPE_MISMATCH!>Obj()<!> // correct error, type check against return type of function "foo"
|
||||
}
|
||||
|
||||
run {
|
||||
|
||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ val a: () -> Unit = l@{
|
||||
|
||||
val b: () -> Unit = l@{
|
||||
// Error, coercion can't be applied at this position!
|
||||
if (true) return@l "hello"
|
||||
if (true) return@l <!RETURN_TYPE_MISMATCH!>"hello"<!>
|
||||
|
||||
// However, this is OK, because here coercion is applied
|
||||
"hello"
|
||||
|
||||
Vendored
+1
-1
@@ -103,7 +103,7 @@ fun main() {
|
||||
select(
|
||||
id { x, y -> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>x<!>.inv() + <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>y<!>.toByte() },
|
||||
id<(Int, Number) -> Int> { x, y -> x.inv() },
|
||||
{} as (Number, Number) -> Int
|
||||
<!RETURN_TYPE_MISMATCH!>{}<!> as (Number, Number) -> Int
|
||||
)
|
||||
|
||||
// Inferring lambda parameter types by a few expected types (a few upper constraints)
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ class Foo<K>
|
||||
fun main() {
|
||||
val x = foo<Int, Foo<<!UNRESOLVED_REFERENCE!>_<!>>> { <!ARGUMENT_TYPE_MISMATCH!>it.toFloat()<!> }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// Related issue: KT-28654
|
||||
|
||||
fun <K> select(): K = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>run { }<!>
|
||||
fun <K> select(): K = <!RETURN_TYPE_MISMATCH!>run { }<!>
|
||||
|
||||
fun test() {
|
||||
val x: Int = select()
|
||||
|
||||
@@ -14,4 +14,4 @@ fun doTheMapThing2(elements: List<CharSequence>): List<String> {
|
||||
return elements.flatMap {
|
||||
<!ARGUMENT_TYPE_MISMATCH!>if (it is String) listOf("Yeah") else null<!> // it's OK with `if`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ abstract class Buggy {
|
||||
}
|
||||
|
||||
val anotherThree : Int
|
||||
get() = <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // does not work here
|
||||
get() = <!RETURN_TYPE_MISMATCH!>coll.find{ it > 3 }<!> // does not work here
|
||||
|
||||
val yetAnotherThree : Int
|
||||
get() = <!TYPE_MISMATCH!>coll.find({ v:Int -> v > 3 })<!> // neither here
|
||||
get() = <!RETURN_TYPE_MISMATCH!>coll.find({ v:Int -> v > 3 })<!> // neither here
|
||||
|
||||
val extendedGetter : Int
|
||||
get() {
|
||||
return <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // not even here!
|
||||
return <!RETURN_TYPE_MISMATCH!>coll.find{ it > 3 }<!> // not even here!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@ class SomeClass {
|
||||
val e = E.VALUE
|
||||
|
||||
val withoutType: LambdaWithReceiver
|
||||
get() = when (e) {
|
||||
get() = <!RETURN_TYPE_MISMATCH!>when (e) {
|
||||
E.VALUE -> { param ->
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>method<!>(param)
|
||||
}
|
||||
}
|
||||
}<!>
|
||||
|
||||
val withExplicitType: LambdaWithReceiver
|
||||
get() = when (e) {
|
||||
get() = <!RETURN_TYPE_MISMATCH!>when (e) {
|
||||
E.VALUE -> { param: Parameter ->
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>method<!>(param)
|
||||
}
|
||||
}
|
||||
}<!>
|
||||
}
|
||||
|
||||
class OtherClass {
|
||||
@@ -38,8 +38,8 @@ class OtherClass {
|
||||
|
||||
val e2 = E.VALUE
|
||||
val staticWithExplicitType: LambdaWithReceiver
|
||||
get() = when (e2) {
|
||||
get() = <!RETURN_TYPE_MISMATCH!>when (e2) {
|
||||
E.VALUE -> { param: Parameter ->
|
||||
<!UNRESOLVED_REFERENCE!>method<!>(param)
|
||||
}
|
||||
}
|
||||
}<!>
|
||||
|
||||
@@ -8,7 +8,7 @@ fun <T> f(expression : T) : G<out T> = G<T>()
|
||||
|
||||
fun foo() : G<Point> {
|
||||
val p = Point()
|
||||
return <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>f<Point>(p)<!>
|
||||
return <!RETURN_TYPE_MISMATCH!>f<Point>(p)<!>
|
||||
}
|
||||
|
||||
class Out<out T>() {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class A() {
|
||||
var x: Int = 0
|
||||
get() = "s"
|
||||
get() = <!RETURN_TYPE_MISMATCH!>"s"<!>
|
||||
set(value: <!WRONG_SETTER_PARAMETER_TYPE!>String<!>) {
|
||||
field = <!ASSIGNMENT_TYPE_MISMATCH!>value<!>
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class A() {
|
||||
get(): <!WRONG_GETTER_RETURN_TYPE("kotlin/Int; kotlin/String")!>String<!> = "s"
|
||||
val z: Int
|
||||
get() {
|
||||
return "s"
|
||||
return <!RETURN_TYPE_MISMATCH!>"s"<!>
|
||||
}
|
||||
|
||||
var a: Any = 1
|
||||
@@ -27,7 +27,7 @@ class A() {
|
||||
}
|
||||
val e = 1
|
||||
get(): <!WRONG_GETTER_RETURN_TYPE!>String<!> {
|
||||
return field
|
||||
return <!RETURN_TYPE_MISMATCH!>field<!>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ fun <T> LiveData<T>.observe(a: Any, observer: (T) -> Unit): Observer<T> {
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun <T> test1(r: Runnable, l: LiveData<T>): Observer<T> = <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>l.observe(r) { }<!> // partial conversion
|
||||
fun <T> test1(r: Runnable, l: LiveData<T>): Observer<T> = <!RETURN_TYPE_MISMATCH!>l.observe(r) { }<!> // partial conversion
|
||||
|
||||
fun <T> test2(r: Runnable, o: Observer<T>, l: LiveData<T>) {
|
||||
val a = l.observe(r, o) // no conversion
|
||||
|
||||
@@ -6,10 +6,10 @@ class A {
|
||||
constructor() {
|
||||
if (1 == 1) {
|
||||
return
|
||||
return 1
|
||||
return <!RETURN_TYPE_MISMATCH!>1<!>
|
||||
}
|
||||
return
|
||||
return <!TYPE_MISMATCH!>foo()<!>
|
||||
return <!RETURN_TYPE_MISMATCH!>foo()<!>
|
||||
}
|
||||
|
||||
fun foo(): Int = 1
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(): Int {
|
||||
var i: Int? = 42
|
||||
i = null
|
||||
return <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>i + 1<!>
|
||||
return <!RETURN_TYPE_MISMATCH!>i + 1<!>
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,4 +9,4 @@ fun case1(a: Boolean) = run { println("d"); return <!RETURN_TYPE_MISMATCH!>true<
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
val case2
|
||||
get() = run { println("d"); return true }
|
||||
get() = run { println("d"); return <!RETURN_TYPE_MISMATCH!>true<!> }
|
||||
|
||||
Vendored
+1
-1
@@ -30,7 +30,7 @@ class Case6 {
|
||||
|
||||
// TESTCASE NUMBER: 7
|
||||
class Case7 {
|
||||
val x: Int get() = null
|
||||
val x: Int get() = <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 8
|
||||
|
||||
Reference in New Issue
Block a user