[NI] Don't fail on captured type that contains type variable

This commit is contained in:
Mikhail Zarechenskiy
2018-01-17 18:27:12 +03:00
parent 145c04e7e2
commit 4cd07f59a0
7 changed files with 63 additions and 15 deletions
@@ -1,17 +1,6 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. 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.resolve.calls.inference.components
@@ -83,10 +72,25 @@ abstract class TypeCheckerContextForConstraintSystem : TypeCheckerContext(errorT
if (subType.anyBound(this::isMyTypeVariable)) {
return simplifyUpperConstraint(subType, superType) && (answer ?: true)
} else {
extractTypeVariableForSubtype(subType)?.let {
return simplifyUpperConstraint(it, superType) && (answer ?: true)
}
return simplifyConstraintForPossibleIntersectionSubType(subType, superType) ?: answer
}
}
// extract type variable only from type like Captured(out T)
private fun extractTypeVariableForSubtype(type: UnwrappedType): UnwrappedType? {
if (type !is NewCapturedType) return null
val projection = type.constructor.projection
return if (projection.projectionKind == Variance.OUT_VARIANCE)
projection.type.takeIf { it is SimpleType && isMyTypeVariable(it) }?.unwrap()
else
null
}
/**
* Foo <: T -- leave as is
*