[NI] Use weaker upper constraint for case {T & Any} <: S

This commit is contained in:
Mikhail Zarechenskiy
2017-06-08 14:01:23 +03:00
parent 18961cc5a9
commit 38d9123a57
@@ -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 <T> id(x: T): T = x
// fun <S> 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) }
}