_1 and such work for Tuples

This commit is contained in:
Andrey Breslav
2012-01-10 12:21:37 +04:00
parent a0134fb0f2
commit 81a3dcf78b
27 changed files with 809 additions and 15 deletions
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.*;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -112,17 +113,24 @@ public class JetStandardClasses {
STANDARD_CLASSES_NAMESPACE,
Collections.<AnnotationDescriptor>emptyList(),
"Tuple" + i);
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION);
for (int j = 0; j < i; j++) {
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createWithDefaultBound(
classDescriptor,
Collections.<AnnotationDescriptor>emptyList(),
true, Variance.OUT_VARIANCE, "T" + j, j));
true, Variance.OUT_VARIANCE, "T" + (j + 1), j);
parameters.add(typeParameterDescriptor);
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, "_" + (j + 1));
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
propertyDescriptor.initialize(new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, true), null);
writableScope.addPropertyDescriptor(propertyDescriptor);
}
writableScope.changeLockLevel(WritableScope.LockLevel.READING);
TUPLE[i] = classDescriptor.initialize(
true,
parameters,
Collections.singleton(getAnyType()),
STUB,
writableScope,
Collections.<ConstructorDescriptor>emptySet(), // TODO
null); // TODO : constructor
TUPLE_CONSTRUCTORS.add(TUPLE[i].getTypeConstructor());
@@ -303,7 +311,9 @@ public class JetStandardClasses {
if (annotations.isEmpty() && arguments.isEmpty()) {
return getUnitType();
}
return new JetTypeImpl(annotations, getTuple(arguments.size()).getTypeConstructor(), false, toProjections(arguments), STUB);
ClassDescriptor tuple = getTuple(arguments.size());
List<TypeProjection> typeArguments = toProjections(arguments);
return new JetTypeImpl(annotations, tuple.getTypeConstructor(), false, typeArguments, tuple.getMemberScope(typeArguments));
}
public static JetType getTupleType(List<JetType> arguments) {
@@ -0,0 +1,6 @@
fun box() : String {
val a = #(1, "2")
if (a._1 != 1) return "Fail 1: ${a._1}"
if (a._2 != "2") return "Fail 1: ${a._2}"
return "OK"
}
@@ -0,0 +1,4 @@
fun foo(a : #(Int, String)) {
a._1 : Int
a._2 : String
}
@@ -0,0 +1,8 @@
package org.jetbrains.jet.codegen;
public class TupleGenTest extends CodegenTestCase {
public void testBasic() {
blackBoxFile("/tuples/basic.jet");
// System.out.println(generateToText());
}
}