diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerContextForConstraintSystem.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerContextForConstraintSystem.kt index 239bb8086de..ac50e77b753 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerContextForConstraintSystem.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/TypeCheckerContextForConstraintSystem.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,6 +117,25 @@ abstract class TypeCheckerContextForConstraintSystem : TypeCheckerContext(errorT return true } +// Consider the following example: +// fun id(x: T): T = x +// fun id2(x: S?, y: S): S = y +// +// fun checkLeftAssoc(a: Int?) : Int { +// return id2(id(a), 3) +// } +// +// fun box() : String { +// return "OK" +// } +// +// here we try to add constraint {Any & T} <: S from `id(a)` +// Previously we thought that if `Any` isn't a subtype of S => T <: S, which is wrong, now we use weaker upper constraint +// TODO: rethink, maybe we should take nullability into account somewhere else + if (notTypeVariables.any { NullabilityChecker.isSubtypeOfAny(it) }) { + return typeVariables.all { simplifyUpperConstraint(it, superType.makeNullableAsSpecified(true)) } + } + return typeVariables.all { simplifyUpperConstraint(it, superType) } }