[NI] Avoid constraints from expected type for effectively empty system

Expression will be checked against expected type later.

 Theoretically, this is not very good, but it aligns with the old
 inference, plus it helps avoiding multiple type mismatch diagnostics.
This commit is contained in:
Mikhail Zarechenskiy
2019-04-17 03:04:58 +03:00
parent 5dea14f4ce
commit bcc8802014
87 changed files with 130 additions and 125 deletions
@@ -148,6 +148,11 @@ class KotlinCallCompleter(
if (returnType == null) return
if (expectedType == null || TypeUtils.noExpectedType(expectedType)) return
// This is needed to avoid multiple mismatch errors as we type check resulting type against expected one later
// Plus, it helps with IDE-tests where it's important to have particular diagnostics.
// Note that it aligns with the old inference, see CallCompleter.completeResolvedCallAndArguments
if (csBuilder.currentStorage().notFixedTypeVariables.isEmpty()) return
// We don't add expected type constraint for constant expression like "1 + 1" because of type coercion for numbers:
// val a: Long = 1 + 1, note that result type of "1 + 1" will be Int and adding constraint with Long will produce type mismatch
if (!resolutionCallbacks.isCompileTimeConstant(resolvedCall, expectedType)) {