Merge remote branch 'origin/master'
This commit is contained in:
@@ -7,10 +7,10 @@ public interface CompilationErrorHandler {
|
|||||||
|
|
||||||
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
|
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void reportError(String message, String fileUrl) {
|
public void reportException(Throwable exception, String fileUrl) {
|
||||||
throw new IllegalStateException(message);
|
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);
|
generateNamespace(namespace);
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
errorHandler.reportError("Exception: " + e.getClass().getCanonicalName() + ": " + e.getMessage(), namespace.getContainingFile().getVirtualFile().getUrl());
|
errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -144,7 +144,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
|||||||
defaultType = new JetTypeImpl(
|
defaultType = new JetTypeImpl(
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
getTypeConstructor(),
|
getTypeConstructor(),
|
||||||
TypeUtils.hasNullableBound(this),
|
TypeUtils.hasNullableLowerBound(this),
|
||||||
Collections.<TypeProjection>emptyList(),
|
Collections.<TypeProjection>emptyList(),
|
||||||
new LazyScopeAdapter(new LazyValue<JetScope>() {
|
new LazyScopeAdapter(new LazyValue<JetScope>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class TypeResolver {
|
|||||||
result[0] = new JetTypeImpl(
|
result[0] = new JetTypeImpl(
|
||||||
annotations,
|
annotations,
|
||||||
typeParameterDescriptor.getTypeConstructor(),
|
typeParameterDescriptor.getTypeConstructor(),
|
||||||
nullable || TypeUtils.hasNullableBound(typeParameterDescriptor),
|
nullable || TypeUtils.hasNullableLowerBound(typeParameterDescriptor),
|
||||||
Collections.<TypeProjection>emptyList(),
|
Collections.<TypeProjection>emptyList(),
|
||||||
getScopeForTypeParameter(typeParameterDescriptor)
|
getScopeForTypeParameter(typeParameterDescriptor)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -97,12 +97,14 @@ public class JetTypeChecker {
|
|||||||
if (!supertype.isNullable() && subtype.isNullable()) {
|
if (!supertype.isNullable() && subtype.isNullable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
subtype = TypeUtils.makeNotNullable(subtype);
|
||||||
|
supertype = TypeUtils.makeNotNullable(supertype);
|
||||||
if (JetStandardClasses.isNothingOrNullableNothing(subtype)) {
|
if (JetStandardClasses.isNothingOrNullableNothing(subtype)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype);
|
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype);
|
||||||
if (closestSupertype == null) {
|
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);
|
return checkSubtypeForTheSameConstructor(closestSupertype, supertype);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public class TypeSubstitutor {
|
|||||||
if (value != null) {
|
if (value != null) {
|
||||||
assert constructor.getDeclarationDescriptor() instanceof TypeParameterDescriptor;
|
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())) {
|
// if (!allows(howThisTypeIsUsed, value.getProjectionKind())) {
|
||||||
// throw new SubstitutionException("!!" + value.toString());
|
// throw new SubstitutionException("!!" + value.toString());
|
||||||
|
|||||||
@@ -385,8 +385,8 @@ public class TypeUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasNullableBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
public static boolean hasNullableLowerBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
|
for (JetType bound : typeParameterDescriptor.getLowerBounds()) {
|
||||||
if (bound.isNullable()) {
|
if (bound.isNullable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -209,7 +209,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
public boolean noCorrespondingSupertype(@NotNull JetType subtype, @NotNull JetType supertype) {
|
public boolean noCorrespondingSupertype(@NotNull JetType subtype, @NotNull JetType supertype) {
|
||||||
boolean result = delegate.noCorrespondingSupertype(subtype, supertype);
|
boolean result = delegate.noCorrespondingSupertype(subtype, supertype);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
println("-- " + subtype + " has supertype corresponding to " + supertype);
|
println("-- " + subtype + " has no supertype corresponding to " + supertype);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -273,9 +273,12 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||||
if (declarationDescriptor instanceof TypeParameterDescriptor) {
|
if (declarationDescriptor instanceof TypeParameterDescriptor) {
|
||||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
|
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
|
||||||
UnknownType unknownType = unknownTypes.get(typeParameterDescriptor);
|
// Checking that this is not a T?, but exactly T
|
||||||
if (unknownType != null) {
|
if (typeParameterDescriptor.getDefaultType().isNullable() == type.isNullable()) {
|
||||||
return unknownType;
|
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
|
//Arrays copy example
|
||||||
class Array<T>(val length : Int) {
|
class Array<T>(val length : Int, val t : T) {
|
||||||
fun get(index : Int) : T { return null }
|
fun get(index : Int) : T { return t }
|
||||||
fun set(index : Int, value : 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
|
namespace test
|
||||||
|
|
||||||
class List<T>(len: Int) {
|
class List<T>(len: Int) {
|
||||||
val a : Array<T> = Array<T>(len)
|
val a : Array<T?> = Array<T?>(len)
|
||||||
|
|
||||||
fun reverse() {
|
fun reverse() {
|
||||||
var i = 0
|
var i = 0
|
||||||
@@ -29,7 +29,7 @@ fun box() : String {
|
|||||||
|
|
||||||
val c = List<Array<Int>>(1)
|
val c = List<Array<Int>>(1)
|
||||||
c.a[0] = Array<Int>(4,{-1})
|
c.a[0] = Array<Int>(4,{-1})
|
||||||
println(c.a[0].size)
|
println(c.a[0]?.size)
|
||||||
|
|
||||||
val e = List<Int>(5)
|
val e = List<Int>(5)
|
||||||
e.a[0] = 0
|
e.a[0] = 0
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ trait WriteOnlyArray<in T> : ISized {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MutableArray<T>(length: Int) : ReadOnlyArray<T>, WriteOnlyArray<T> {
|
class MutableArray<T>(length: Int, init : fun(Int) : T) : ReadOnlyArray<T>, WriteOnlyArray<T> {
|
||||||
private val array = Array<T>(length)
|
private val array = Array<T>(length, init)
|
||||||
|
|
||||||
override fun get(index : Int) : T = array[index]
|
override fun get(index : Int) : T = array[index]
|
||||||
override fun set(index : Int, value : T) : Unit { array[index] = value }
|
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 {
|
fun box() : String {
|
||||||
var a = MutableArray<Int> (4)
|
var a = MutableArray<Int> (4, {0})
|
||||||
a [0] = 10
|
a [0] = 10
|
||||||
a.set(1, 2, 13)
|
a.set(1, 2, 13)
|
||||||
a [3] = 40
|
a [3] = 40
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateMultiGenerics () throws Exception {
|
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());
|
System.out.println(generateToText());
|
||||||
Method foo = generateFunction();
|
Method foo = generateFunction();
|
||||||
Object invoke = foo.invoke(null);
|
Object invoke = foo.invoke(null);
|
||||||
|
|||||||
@@ -56,6 +56,6 @@ namespace io {
|
|||||||
|
|
||||||
namespace string {
|
namespace string {
|
||||||
fun String.replaceAll(pattern : String, replacement : String) : 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)
|
// Note: \u000A is Unicode representation of linefeed (LF)
|
||||||
val c : Char = 0x000A .chr;
|
val c : Char = 0x000A .chr;
|
||||||
println(c);
|
println(c);
|
||||||
println("a\u \u0 \u00 \u000 \u0000 \u0AaA \u0AAz.length( ) + \u0022b")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
if (!errors) {
|
if (!errors) {
|
||||||
generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
|
generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void reportError(String message, String fileUrl) {
|
public void reportException(Throwable exception, String fileUrl) {
|
||||||
compileContext.addMessage(CompilerMessageCategory.WARNING, message, fileUrl, 0, 0);
|
compileContext.addMessage(CompilerMessageCategory.WARNING, exception.getClass().getCanonicalName() + ": " + exception.getMessage(), fileUrl, 0, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
///////////
|
///////////
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Arrays copy example
|
//Arrays copy example
|
||||||
class Array<T>(val length : Int) {
|
class Array<T>(val length : Int, val t : T) {
|
||||||
fun get(index : Int) : T { return null }
|
fun get(index : Int) : T { return t }
|
||||||
fun set(index : Int, value : T) { /* ... */ }
|
fun set(index : Int, value : T) { /* ... */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user