Create hack for exception about "Empty intersection for types".

Hackaround for KT-11266, EA-79963, EA-72093,  EA-79976.
This commit is contained in:
Stanislav Erokhin
2016-06-16 21:17:42 +03:00
parent 490ff621b6
commit 01430b4b99
5 changed files with 55 additions and 0 deletions
@@ -117,6 +117,11 @@ public class TypeIntersector {
// TODO: maybe return the most specific among the types that are subtypes to all others in the `nullabilityStripped`?
// TODO: e.g. among {Int, Int?, Int!}, return `Int` (now it returns `Int!`).
KotlinType bestRepresentative = FlexibleTypesKt.singleBestRepresentative(nullabilityStripped);
if (bestRepresentative == null) {
bestRepresentative = UtilsKt.hackForTypeIntersector(nullabilityStripped);
}
if (bestRepresentative == null) {
throw new AssertionError("Empty intersection for types " + types);
}
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2016 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.
*/
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
/**
* This is temporary hack for type intersector.
*
* It is almost save, because:
* - it running only if general algorithm is failed
* - returned type is subtype of all [types].
*
* But it is hack, because it can give unstable result, but it better than exception.
* See KT-11266.
*/
internal fun hackForTypeIntersector(types: Collection<KotlinType>): KotlinType? {
if (types.size < 2) return types.firstOrNull()
return types.firstOrNull { candidate ->
types.all {
KotlinTypeChecker.ERROR_TYPES_ARE_EQUAL_TO_ANYTHING.isSubtypeOf(candidate, it)
}
}
}
@@ -0,0 +1,2 @@
fun foo(first: Array<Any?>, second: Array<Any?>) = Pair(first.toCollection(<!NO_VALUE_FOR_PARAMETER!>)<!>, second.toCollection(<!NO_VALUE_FOR_PARAMETER!>)<!>)
@@ -0,0 +1,3 @@
package
public fun foo(/*0*/ first: kotlin.Array<kotlin.Any?>, /*1*/ second: kotlin.Array<kotlin.Any?>): kotlin.Pair<kotlin.collections.MutableCollection<kotlin.Any?>, kotlin.collections.MutableCollection<kotlin.Any?>>
@@ -784,6 +784,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
doTest(fileName);
}
@TestMetadata("kt11266.kt")
public void testKt11266() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/kt11266.kt");
doTest(fileName);
}
@TestMetadata("kt1558.kt")
public void testKt1558() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.kt");