From 1e3f2889a4f6d4f5b5fecd8028536d4c599251c6 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 10 Nov 2011 19:44:47 +0300 Subject: [PATCH] KT-336 Can't infer type parameter for ArrayList in a generic function (Exception in type inference) KT-335 Type inference fails on Collections.sort --- .../lang/types/inference/ConstraintSystemImpl.java | 1 + .../full/regression/kt335.336.jet | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 compiler/testData/checkerWithErrorTypes/full/regression/kt335.336.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/inference/ConstraintSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/inference/ConstraintSystemImpl.java index a569a0beb1f..30f28d9ffa7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/inference/ConstraintSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/inference/ConstraintSystemImpl.java @@ -376,6 +376,7 @@ public class ConstraintSystemImpl implements ConstraintSystem { DeclarationDescriptor declarationDescriptor = key.getDeclarationDescriptor(); if (declarationDescriptor instanceof TypeParameterDescriptor) { TypeParameterDescriptor descriptor = (TypeParameterDescriptor) declarationDescriptor; + if (!unknownTypes.containsKey(descriptor)) return null; println(descriptor + " |-> " + getValue(descriptor)); return new TypeProjection(getValue(descriptor)); } diff --git a/compiler/testData/checkerWithErrorTypes/full/regression/kt335.336.jet b/compiler/testData/checkerWithErrorTypes/full/regression/kt335.336.jet new file mode 100644 index 00000000000..46537f0041c --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/full/regression/kt335.336.jet @@ -0,0 +1,14 @@ +// KT-336 Can't infer type parameter for ArrayList in a generic function (Exception in type inference) +// KT-335 Type inference fails on Collections.sort + +import java.util.* +import java.lang.Comparable as Comparable + +fun > List.sort() { + Collections.sort(this) // Error here +} + +fun List.plus(other : List) : List { + val result = ArrayList(this) + return result +}