[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:
+5
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user