Merge remote branch 'origin/master'

This commit is contained in:
Alex Tkachman
2011-11-12 19:13:51 +02:00
17 changed files with 43 additions and 28 deletions
@@ -7,10 +7,10 @@ public interface CompilationErrorHandler {
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
@Override
public void reportError(String message, String fileUrl) {
throw new IllegalStateException(message);
public void reportException(Throwable exception, String fileUrl) {
throw new IllegalStateException(exception);
}
};
void reportError(String message, String fileUrl);
void reportException(Throwable exception, String fileUrl);
}
@@ -112,7 +112,7 @@ public class GenerationState {
generateNamespace(namespace);
}
catch (Throwable e) {
errorHandler.reportError("Exception: " + e.getClass().getCanonicalName() + ": " + e.getMessage(), namespace.getContainingFile().getVirtualFile().getUrl());
errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl());
}
}
}
@@ -144,7 +144,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
defaultType = new JetTypeImpl(
Collections.<AnnotationDescriptor>emptyList(),
getTypeConstructor(),
TypeUtils.hasNullableBound(this),
TypeUtils.hasNullableLowerBound(this),
Collections.<TypeProjection>emptyList(),
new LazyScopeAdapter(new LazyValue<JetScope>() {
@Override
@@ -78,7 +78,7 @@ public class TypeResolver {
result[0] = new JetTypeImpl(
annotations,
typeParameterDescriptor.getTypeConstructor(),
nullable || TypeUtils.hasNullableBound(typeParameterDescriptor),
nullable || TypeUtils.hasNullableLowerBound(typeParameterDescriptor),
Collections.<TypeProjection>emptyList(),
getScopeForTypeParameter(typeParameterDescriptor)
);
@@ -97,12 +97,14 @@ public class JetTypeChecker {
if (!supertype.isNullable() && subtype.isNullable()) {
return false;
}
subtype = TypeUtils.makeNotNullable(subtype);
supertype = TypeUtils.makeNotNullable(supertype);
if (JetStandardClasses.isNothingOrNullableNothing(subtype)) {
return true;
}
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype);
if (closestSupertype == null) {
if (!constraintBuilder.noCorrespondingSupertype(subtype, supertype)) return false;
return constraintBuilder.noCorrespondingSupertype(subtype, supertype); // if this returns true, there still isn't any supertype to continue with
}
return checkSubtypeForTheSameConstructor(closestSupertype, supertype);
@@ -130,7 +130,7 @@ public class TypeSubstitutor {
if (value != null) {
assert constructor.getDeclarationDescriptor() instanceof TypeParameterDescriptor;
return substitutionResult((TypeParameterDescriptor) constructor.getDeclarationDescriptor(), howThisTypeIsUsed, Variance.INVARIANT, value).getType();
return TypeUtils.makeNullableIfNeeded(substitutionResult((TypeParameterDescriptor) constructor.getDeclarationDescriptor(), howThisTypeIsUsed, Variance.INVARIANT, value).getType(), type.isNullable());
// if (!allows(howThisTypeIsUsed, value.getProjectionKind())) {
// throw new SubstitutionException("!!" + value.toString());
@@ -385,8 +385,8 @@ public class TypeUtils {
return result;
}
public static boolean hasNullableBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
public static boolean hasNullableLowerBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
for (JetType bound : typeParameterDescriptor.getLowerBounds()) {
if (bound.isNullable()) {
return true;
}
@@ -209,7 +209,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
public boolean noCorrespondingSupertype(@NotNull JetType subtype, @NotNull JetType supertype) {
boolean result = delegate.noCorrespondingSupertype(subtype, supertype);
if (!result) {
println("-- " + subtype + " has supertype corresponding to " + supertype);
println("-- " + subtype + " has no supertype corresponding to " + supertype);
}
return result;
}
@@ -273,9 +273,12 @@ public class ConstraintSystemImpl implements ConstraintSystem {
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
if (declarationDescriptor instanceof TypeParameterDescriptor) {
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
UnknownType unknownType = unknownTypes.get(typeParameterDescriptor);
if (unknownType != null) {
return unknownType;
// Checking that this is not a T?, but exactly T
if (typeParameterDescriptor.getDefaultType().isNullable() == type.isNullable()) {
UnknownType unknownType = unknownTypes.get(typeParameterDescriptor);
if (unknownType != null) {
return unknownType;
}
}
}
@@ -18,8 +18,8 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
}
//Arrays copy example
class Array<T>(val length : Int) {
fun get(index : Int) : T { return null }
class Array<T>(val length : Int, val t : T) {
fun get(index : Int) : T { return t }
fun set(index : Int, value : T) { /* ... */ }
}
@@ -0,0 +1,11 @@
// KT-313 Bug in substitutions in a function returning its type parameter T
fun <T> Iterable<T>.join(separator : String?) : String {
return separator.npe()
}
fun <T : Any> T?.npe() : T {
if (this == null)
throw NullPointerException()
return this;
}
@@ -1,7 +1,7 @@
namespace test
class List<T>(len: Int) {
val a : Array<T> = Array<T>(len)
val a : Array<T?> = Array<T?>(len)
fun reverse() {
var i = 0
@@ -29,7 +29,7 @@ fun box() : String {
val c = List<Array<Int>>(1)
c.a[0] = Array<Int>(4,{-1})
println(c.a[0].size)
println(c.a[0]?.size)
val e = List<Int>(5)
e.a[0] = 0
+3 -3
View File
@@ -36,8 +36,8 @@ trait WriteOnlyArray<in T> : ISized {
}
}
class MutableArray<T>(length: Int) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<T>(length)
class MutableArray<T>(length: Int, init : fun(Int) : T) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<T>(length, init)
override fun get(index : Int) : T = array[index]
override fun set(index : Int, value : T) : Unit { array[index] = value }
@@ -47,7 +47,7 @@ class MutableArray<T>(length: Int) : ReadOnlyArray<T>, WriteOnlyArray<T> {
}
fun box() : String {
var a = MutableArray<Int> (4)
var a = MutableArray<Int> (4, {0})
a [0] = 10
a.set(1, 2, 13)
a [3] = 40
@@ -38,7 +38,7 @@ public class ArrayGenTest extends CodegenTestCase {
}
public void testCreateMultiGenerics () throws Exception {
loadText("class L<T>() { val a = Array<T>(5) } fun foo() = L<Int>.a");
loadText("class L<T>() { val a = Array<T?>(5) } fun foo() = L<Int>.a");
System.out.println(generateToText());
Method foo = generateFunction();
Object invoke = foo.invoke(null);
+1 -1
View File
@@ -56,6 +56,6 @@ namespace io {
namespace string {
fun String.replaceAll(pattern : String, replacement : String) : String {
return java.util.regex.Pattern.compile(pattern).matcher(this).replaceAll(replacement).npe()
return (this as java.lang.String).replace(pattern as CharSequence, replacement as CharSequence).npe()
}
}
@@ -15,5 +15,4 @@ fun main(args : Array<String>) {
// Note: \u000A is Unicode representation of linefeed (LF)
val c : Char = 0x000A .chr;
println(c);
println("a\u \u0 \u00 \u000 \u0000 \u0AaA \u0AAz.length( ) + \u0022b")
}
@@ -104,8 +104,8 @@ public class JetCompiler implements TranslatingCompiler {
if (!errors) {
generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
@Override
public void reportError(String message, String fileUrl) {
compileContext.addMessage(CompilerMessageCategory.WARNING, message, fileUrl, 0, 0);
public void reportException(Throwable exception, String fileUrl) {
compileContext.addMessage(CompilerMessageCategory.WARNING, exception.getClass().getCanonicalName() + ": " + exception.getMessage(), fileUrl, 0, 0);
}
});
///////////
+2 -2
View File
@@ -18,8 +18,8 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
}
//Arrays copy example
class Array<T>(val length : Int) {
fun get(index : Int) : T { return null }
class Array<T>(val length : Int, val t : T) {
fun get(index : Int) : T { return t }
fun set(index : Int, value : T) { /* ... */ }
}