Merge branch 'master' of ssh://git.labs.intellij.net/jet

This commit is contained in:
svtk
2011-09-13 12:20:48 +04:00
21 changed files with 385 additions and 161 deletions
+25 -1
View File
@@ -1,10 +1,16 @@
class A() {}
class B<T>() {
open class B<T>() {
fun isT (a : Any?) : Boolean {
return a is T
}
}
class C() : B<String>() {
}
class D<T>() : B<B<T>>() {
}
fun t1() : Boolean {
val a = A()
if(a !is A) return false
@@ -148,6 +154,18 @@ fun t24 () : Boolean {
return true
}
fun t25 () : Boolean {
val c = C()
if(!c.isT("aaa")) return false
return true
}
fun t26 () : Boolean {
val d = D<String>()
if(!d.isT(B<String>())) return false
return true
}
fun box() : String {
if(!t1()) {
return "t1 failed"
@@ -221,5 +239,11 @@ fun box() : String {
if(!t24()) {
return "t24 failed"
}
if(!t25()) {
return "t25 failed"
}
if(!t26()) {
return "t26 failed"
}
return "OK"
}
@@ -0,0 +1,4 @@
// KT-297 Overload resolution ambiguity with required in trait
trait ALE<T> : java.util.ArrayList<T> {
fun getOrValue(index: Int, value : T) : T = if(index >= 0 && index < size()) get(index) else value
}
+15
View File
@@ -0,0 +1,15 @@
trait AL {
fun get(index: Int) : Any? = null
}
trait ALE<T> : AL {
fun getOrNull(index: Int, value : T) = get(index) as? T ?: value
}
class SmartArrayList() : ALE<String> {
}
fun box() : String {
val c = SmartArrayList()
return if("239" == c.getOrNull(0, "239")) "OK" else "fail"
}
@@ -0,0 +1,15 @@
open class AL<T> {
fun get(index: Int) : T? = null
}
trait ALE<T> : AL<T> {
fun getOrValue(index: Int, value : T) : T = get(index) ?: value
}
class SmartArrayList() : ALE<String>, AL<String> {
}
fun box() : String {
val c = SmartArrayList()
return if("239" == c.getOrValue(0, "239")) "OK" else "fail"
}
@@ -0,0 +1,9 @@
// KT-300 Overload ambiguity while accessing range
class MyRange() : Range<Int> {
~in~override fun contains(item: Int) = true
}
fun foo(x: Int?, range: MyRange) {
x `in`in range // Int? found, but Int expected
}
@@ -10,4 +10,14 @@ public class TraitsTest extends CodegenTestCase {
blackBoxFile("traits/simple.jet");
System.out.println(generateToText());
}
public void testWithRequired () throws Exception {
blackBoxFile("traits/withRequired.jet");
System.out.println(generateToText());
}
public void testMultiple () throws Exception {
// blackBoxFile("traits/multiple.jet");
// System.out.println(generateToText());
}
}
@@ -131,6 +131,7 @@ public class TypeInfoTest extends CodegenTestCase {
public void testKt259() throws Exception {
blackBoxFile("regressions/kt259.jet");
System.out.println(generateToText());
}
}
@@ -6,19 +6,20 @@ import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetTestCaseBase;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetChangeUtil;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.java.JavaPackageScope;
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.parsing.JetParsingTest;
import java.io.File;
@@ -34,6 +35,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private ClassDefinitions classDefinitions;
private ClassDescriptorResolver classDescriptorResolver;
private JetScope scopeWithImports;
private TypeResolver typeResolver;
@Override
public void setUp() throws Exception {
@@ -43,6 +45,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
classDefinitions = new ClassDefinitions();
classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
typeResolver = new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true);
}
@Override
@@ -592,7 +595,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
if (CLASSES.isEmpty()) {
for (String classDeclaration : CLASS_DECLARATIONS) {
JetClass classElement = JetChangeUtil.createClass(getProject(), classDeclaration);
ClassDescriptor classDescriptor = classDescriptorResolver.resolveClassDescriptor(this, classElement);
ClassDescriptor classDescriptor = resolveClassDescriptor(this, classElement);
CLASSES.put(classDescriptor.getName(), classDescriptor);
}
}
@@ -622,5 +625,91 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
return writableFunctionGroup;
}
};
@Nullable
public ClassDescriptor resolveClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement) {
final ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
scope.getContainingDeclaration(),
Collections.<AnnotationDescriptor>emptyList(),
JetPsiUtil.safeName(classElement.getName()));
BindingTrace trace = JetTestUtils.DUMMY_TRACE;
trace.record(BindingContext.CLASS, classElement, classDescriptor);
final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler());
// This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters
= classDescriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters());
classDescriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters);
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic
Collection<JetType> supertypes = delegationSpecifiers.isEmpty()
? Collections.singleton(JetStandardClasses.getAnyType())
: classDescriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver);
// for (JetType supertype: supertypes) {
// if (supertype.getConstructor().isSealed()) {
// trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype);
// }
// }
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, trace.getErrorHandler());
List<JetDeclaration> declarations = classElement.getDeclarations();
for (JetDeclaration declaration : declarations) {
declaration.accept(new JetVisitorVoid() {
@Override
public void visitProperty(JetProperty property) {
if (property.getPropertyTypeRef() != null) {
memberDeclarations.addVariableDescriptor(classDescriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property));
} else {
// TODO : Caution: a cyclic dependency possible
throw new UnsupportedOperationException();
}
}
@Override
public void visitNamedFunction(JetNamedFunction function) {
if (function.getReturnTypeRef() != null) {
memberDeclarations.addFunctionDescriptor(classDescriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function));
} else {
// TODO : Caution: a cyclic dependency possible
throw new UnsupportedOperationException();
}
}
@Override
public void visitJetElement(JetElement element) {
throw new UnsupportedOperationException(element.toString());
}
});
}
WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
classDescriptor.initialize(
!open,
typeParameters,
supertypes,
memberDeclarations,
constructors,
null
);
for (JetConstructor constructor : classElement.getSecondaryConstructors()) {
ConstructorDescriptorImpl functionDescriptor = classDescriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor);
functionDescriptor.setReturnType(classDescriptor.getDefaultType());
constructors.addFunction(functionDescriptor);
}
ConstructorDescriptorImpl primaryConstructorDescriptor = classDescriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement);
if (primaryConstructorDescriptor != null) {
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
constructors.addFunction(primaryConstructorDescriptor);
classDescriptor.setPrimaryConstructor(primaryConstructorDescriptor);
}
return classDescriptor;
}
}
}