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

This commit is contained in:
James Strachan
2011-12-18 07:18:30 +00:00
21 changed files with 193 additions and 46 deletions
+33 -1
View File
@@ -103,6 +103,38 @@ trait Iterable<out T> {
fun iterator() : Iterator<T>
}
trait ByteIterable : Iterable<Byte> {
override fun iterator() : ByteIterator
}
trait ShortIterable : Iterable<Short> {
override fun iterator() : ShortIterator
}
trait IntIterable : Iterable<Int> {
override fun iterator() : IntIterator
}
trait LongIterable : Iterable<Long> {
override fun iterator() : LongIterator
}
trait FloatIterable : Iterable<Float> {
override fun iterator() : FloatIterator
}
trait DoubleIterable : Iterable<Double> {
override fun iterator() : DoubleIterator
}
trait BooleanIterable : Iterable<Boolean> {
override fun iterator() : BooleanIterator
}
trait CharIterable : Iterable<Char> {
override fun iterator() : CharIterator
}
fun Array<T>(val size : Int) : Array<T?>
class Array<T>(val size : Int, init : fun(Int) : T) {
@@ -230,7 +262,7 @@ trait Range<in T : Comparable<T>> {
fun contains(item : T) : Boolean
}
class IntRange(val start : Int, size : Int, reversed : Boolean = false) : Range<Int>, Iterable<Int> {
class IntRange(val start : Int, size : Int, reversed : Boolean = false) : Range<Int>, IntIterable {
fun iterator () : Iterator<Int>
fun contains (elem: Int) : Boolean
@@ -556,10 +556,10 @@ public class JetFlowInformationProvider {
JetDeclaration element = ((VariableDeclarationInstruction) instruction).getVariableDeclarationElement();
if (element instanceof JetNamedDeclaration) {
PsiElement nameIdentifier = ((JetNamedDeclaration) element).getNameIdentifier();
PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : element;
if (nameIdentifier == null) return;
if (variableStatus == null || variableStatus == VariableStatus.UNUSED) {
if (element instanceof JetProperty) {
trace.report(Errors.UNUSED_VARIABLE.on((JetProperty) element, elementToMark, variableDescriptor));
trace.report(Errors.UNUSED_VARIABLE.on((JetProperty) element, nameIdentifier, variableDescriptor));
}
else if (element instanceof JetParameter) {
PsiElement psiElement = element.getParent().getParent();
@@ -569,13 +569,13 @@ public class JetFlowInformationProvider {
assert descriptor instanceof FunctionDescriptor;
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
if (!isMain && !functionDescriptor.getModality().isOverridable() && functionDescriptor.getOverriddenDescriptors().isEmpty()) {
trace.report(Errors.UNUSED_PARAMETER.on((JetParameter) element, elementToMark, variableDescriptor));
trace.report(Errors.UNUSED_PARAMETER.on((JetParameter) element, nameIdentifier, variableDescriptor));
}
}
}
}
else if (variableStatus == VariableStatus.ONLY_WRITTEN && element instanceof JetProperty) {
trace.report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on((JetNamedDeclaration) element, elementToMark, variableDescriptor));
trace.report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on((JetNamedDeclaration) element, nameIdentifier, variableDescriptor));
}
else if (variableStatus == VariableStatus.WRITTEN && element instanceof JetProperty) {
JetExpression initializer = ((JetProperty) element).getInitializer();
@@ -221,18 +221,17 @@ public class DeclarationsChecker {
boolean backingFieldRequired = context.getTrace().getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor);
PsiElement nameIdentifier = property.getNameIdentifier();
ASTNode nameNode = nameIdentifier == null ? property.getNode() : nameIdentifier.getNode();
if (inTrait && backingFieldRequired && hasAccessorImplementation) {
context.getTrace().report(BACKING_FIELD_IN_TRAIT.on(nameNode));
if (inTrait && backingFieldRequired && hasAccessorImplementation && nameIdentifier != null) {
context.getTrace().report(BACKING_FIELD_IN_TRAIT.on(nameIdentifier));
}
if (initializer == null) {
if (backingFieldRequired && !inTrait && !context.getTrace().getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor)) {
if (nameIdentifier != null && backingFieldRequired && !inTrait && !context.getTrace().getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor)) {
if (classDescriptor == null || hasAccessorImplementation) {
context.getTrace().report(MUST_BE_INITIALIZED.on(nameNode));
context.getTrace().report(MUST_BE_INITIALIZED.on(nameIdentifier));
}
else {
context.getTrace().report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property, nameNode));
context.getTrace().report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property, nameIdentifier));
}
}
return;
@@ -117,10 +117,10 @@ public class OverrideResolver {
else if (klass instanceof JetObjectDeclaration) {
nameIdentifier = ((JetObjectDeclaration) klass).getNameIdentifier();
}
PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : klass;
if (nameIdentifier == null) return;
for (CallableMemberDescriptor memberDescriptor : manyImpl) {
context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(elementToMark, klass, memberDescriptor));
context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
break;
}
@@ -130,7 +130,7 @@ public class OverrideResolver {
}
for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) {
context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(elementToMark, klass, memberDescriptor));
context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
break;
}
@@ -19,6 +19,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
import org.jetbrains.jet.lexer.JetToken;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.*;
@@ -344,7 +345,7 @@ public class CallResolver {
if (callElement instanceof JetBinaryExpression) {
JetBinaryExpression binaryExpression = (JetBinaryExpression) callElement;
JetSimpleNameExpression operationReference = binaryExpression.getOperationReference();
String operationString = operationReference.getReferencedNameElementType() == JetTokens.IDENTIFIER ? operationReference.getText() : OperatorConventions.getNameForOperationSymbol(operationReference.getReferencedNameElementType());
String operationString = operationReference.getReferencedNameElementType() == JetTokens.IDENTIFIER ? operationReference.getText() : OperatorConventions.getNameForOperationSymbol((JetToken) operationReference.getReferencedNameElementType());
JetExpression right = binaryExpression.getRight();
if (right != null) {
trace.report(UNSAFE_INFIX_CALL.on(reference, binaryExpression.getLeft().getText(), operationString, right.getText()));
@@ -506,15 +507,6 @@ public class CallResolver {
}
else {
tracing.typeInferenceFailed(temporaryTrace, solution.getStatus());
// // Substitute DONT_CARE types to make further type checking as tolerant as possible
// D candidateWithDontCares = (D) candidate.substitute(TypeSubstitutor.makeConstantSubstitutor(candidate.getTypeParameters(), DONT_CARE));
// if (candidateWithDontCares == null) {
// candidateWithDontCares = (D) candidate.substitute(TypeSubstitutor.makeConstantSubstitutor(candidate.getTypeParameters(), Variance.INVARIANT, DONT_CARE));
// }
// if (!ErrorUtils.isErrorType(candidateWithDontCares.getReturnType())) {
// // Returning an error type provokes overload resolution ambiguities that mask errors
// candidateCall.setResultingDescriptor(candidateWithDontCares);
// }
candidateCall.setStatus(OTHER_ERROR.combine(checkAllValueArguments(scope, tracing, task, candidateCall)));
}
}
@@ -1,10 +1,11 @@
package org.jetbrains.jet.lang.types.expressions;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lexer.JetToken;
import org.jetbrains.jet.lexer.JetTokens;
/**
@@ -12,6 +13,10 @@ import org.jetbrains.jet.lexer.JetTokens;
*/
public class OperatorConventions {
public static final String EQUALS = "equals";
public static final String COMPARE_TO = "compareTo";
public static final String CONTAINS = "contains";
private OperatorConventions() {}
public static final ImmutableSet<String> NUMBER_CONVERSIONS = ImmutableSet.of(
@@ -23,7 +28,7 @@ public class OperatorConventions {
"int"
);
public static final ImmutableMap<IElementType, String> UNARY_OPERATION_NAMES = ImmutableMap.<IElementType, String>builder()
public static final ImmutableBiMap<JetToken, String> UNARY_OPERATION_NAMES = ImmutableBiMap.<JetToken, String>builder()
.put(JetTokens.PLUSPLUS, "inc")
.put(JetTokens.MINUSMINUS, "dec")
.put(JetTokens.PLUS, "plus")
@@ -31,7 +36,7 @@ public class OperatorConventions {
.put(JetTokens.EXCL, "not")
.build();
public static final ImmutableMap<IElementType, String> BINARY_OPERATION_NAMES = ImmutableMap.<IElementType, String>builder()
public static final ImmutableBiMap<JetToken, String> BINARY_OPERATION_NAMES = ImmutableBiMap.<JetToken, String>builder()
.put(JetTokens.MUL, "times")
.put(JetTokens.PLUS, "plus")
.put(JetTokens.MINUS, "minus")
@@ -41,11 +46,22 @@ public class OperatorConventions {
.put(JetTokens.RANGE, "rangeTo")
.build();
public static final ImmutableSet<IElementType> COMPARISON_OPERATIONS = ImmutableSet.<IElementType>of(JetTokens.LT, JetTokens.GT, JetTokens.LTEQ, JetTokens.GTEQ);
public static final ImmutableSet<IElementType> EQUALS_OPERATIONS = ImmutableSet.<IElementType>of(JetTokens.EQEQ, JetTokens.EXCLEQ);
public static final ImmutableSet<JetToken> NOT_OVERLOADABLE =
ImmutableSet.<JetToken>of(JetTokens.ANDAND, JetTokens.OROR, JetTokens.ELVIS);
public static final ImmutableSet<JetToken> INCREMENT_OPERATIONS =
ImmutableSet.<JetToken>of(JetTokens.PLUSPLUS, JetTokens.MINUSMINUS);
public static final ImmutableSet<IElementType> IN_OPERATIONS = ImmutableSet.<IElementType>of(JetTokens.IN_KEYWORD, JetTokens.NOT_IN);
public static final ImmutableMap<IElementType, String> ASSIGNMENT_OPERATIONS = ImmutableMap.<IElementType, String>builder()
public static final ImmutableSet<JetToken> COMPARISON_OPERATIONS =
ImmutableSet.<JetToken>of(JetTokens.LT, JetTokens.GT, JetTokens.LTEQ, JetTokens.GTEQ);
public static final ImmutableSet<JetToken> EQUALS_OPERATIONS =
ImmutableSet.<JetToken>of(JetTokens.EQEQ, JetTokens.EXCLEQ);
public static final ImmutableSet<JetToken> IN_OPERATIONS =
ImmutableSet.<JetToken>of(JetTokens.IN_KEYWORD, JetTokens.NOT_IN);
public static final ImmutableBiMap<JetToken, String> ASSIGNMENT_OPERATIONS = ImmutableBiMap.<JetToken, String>builder()
.put(JetTokens.MULTEQ, "timesAssign")
.put(JetTokens.DIVEQ, "divAssign")
.put(JetTokens.PERCEQ, "modAssign")
@@ -53,7 +69,7 @@ public class OperatorConventions {
.put(JetTokens.MINUSEQ, "minusAssign")
.build();
public static final ImmutableMap<IElementType, IElementType> ASSIGNMENT_OPERATION_COUNTERPARTS = ImmutableMap.<IElementType, IElementType>builder()
public static final ImmutableMap<JetToken, JetToken> ASSIGNMENT_OPERATION_COUNTERPARTS = ImmutableMap.<JetToken, JetToken>builder()
.put(JetTokens.MULTEQ, JetTokens.MUL)
.put(JetTokens.DIVEQ, JetTokens.DIV)
.put(JetTokens.PERCEQ, JetTokens.PERC)
@@ -62,17 +78,16 @@ public class OperatorConventions {
.build();
@Nullable
public static String getNameForOperationSymbol(@NotNull IElementType token) {
public static String getNameForOperationSymbol(@NotNull JetToken token) {
String name = UNARY_OPERATION_NAMES.get(token);
if (name != null) return name;
name = BINARY_OPERATION_NAMES.get(token);
if (name != null) return name;
name = ASSIGNMENT_OPERATIONS.get(token);
if (name != null) return name;
if (COMPARISON_OPERATIONS.contains(token)) return "compareTo";
if (EQUALS_OPERATIONS.contains(token)) return "equals";
if (IN_OPERATIONS.contains(token)) return "contains";
if (COMPARISON_OPERATIONS.contains(token)) return COMPARE_TO;
if (EQUALS_OPERATIONS.contains(token)) return EQUALS;
if (IN_OPERATIONS.contains(token)) return CONTAINS;
return null;
}
}
}
@@ -0,0 +1,16 @@
namespace one_extends_base
open class Base<T>(name : T?) {
var myName : T?
{
$myName = name
}
}
open class One<T, K>(name : T?, second : K?) : Base<T?>(name) {
var mySecond : K?
{
$mySecond = second
}
}
fun box() = if(One<String, Int>("ola", 0).myName == "ola") "OK" else "fail"
@@ -0,0 +1,3 @@
val <T> Array<T>.length : Int get() = this.size
fun box() = if(Array(10, {1}).length == 10) "OK" else "fail"
@@ -0,0 +1,8 @@
//KT-843 Don't highlight incomplete variables as unused
namespace kt843
fun main(args : Array<String>) {
// Integer type
val // this word is grey, which looks strange
<!SYNTAX!>}<!SYNTAX!><!><!>
@@ -12,6 +12,11 @@ public class ArrayGenTest extends CodegenTestCase {
// System.out.println(generateToText());
}
public void testKt779 () throws Exception {
blackBoxFile("regressions/kt779.jet");
// System.out.println(generateToText());
}
public void testCreateMultiInt () throws Exception {
loadText("fun foo() = Array<Array<Int>> (5, { Array<Int>(it, {239}) })");
Method foo = generateFunction();
@@ -138,6 +138,11 @@ public class TypeInfoTest extends CodegenTestCase {
// System.out.println(generateToText());
}
public void testKt511() throws Exception {
blackBoxFile("regressions/kt511.jet");
// System.out.println(generateToText());
}
public void testInner() throws Exception {
blackBoxFile("typeInfo/inner.jet");
System.out.println(generateToText());
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface BooleanIterable extends Iterable<Boolean> {
@Override
BooleanIterator iterator();
}
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface ByteIterable extends Iterable<Byte> {
@Override
ByteIterator iterator();
}
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface CharIterable extends Iterable<Character> {
@Override
CharIterator iterator();
}
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface DoubleIterable extends Iterable<Double> {
@Override
DoubleIterator iterator();
}
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface FloatIterable extends Iterable<Float> {
@Override
FloatIterator iterator();
}
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface IntIterable extends Iterable<Integer> {
@Override
IntIterator iterator();
}
+4 -4
View File
@@ -2,7 +2,7 @@ package jet;
import jet.typeinfo.TypeInfo;
public final class IntRange implements Range<Integer>, Iterable<Integer>, JetObject {
public final class IntRange implements Range<Integer>, IntIterable, JetObject {
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(IntRange.class, false);
private final int start;
@@ -39,7 +39,7 @@ public final class IntRange implements Range<Integer>, Iterable<Integer>, JetObj
}
@Override
public Iterator<Integer> iterator() {
public IntIterator iterator() {
return new MyIterator(start, count);
}
@@ -66,7 +66,7 @@ public final class IntRange implements Range<Integer>, Iterable<Integer>, JetObj
}
}
private static class MyIterator implements Iterator<Integer> {
private static class MyIterator extends IntIterator {
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(MyIterator.class, false);
private int cur;
@@ -86,7 +86,7 @@ public final class IntRange implements Range<Integer>, Iterable<Integer>, JetObj
}
@Override
public Integer next() {
public int nextInt() {
count--;
if(reversed) {
return cur--;
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface LongIterable extends Iterable<Long> {
@Override
LongIterator iterator();
}
+4 -4
View File
@@ -2,7 +2,7 @@ package jet;
import jet.typeinfo.TypeInfo;
public final class LongRange implements Range<Long>, Iterable<Long>, JetObject {
public final class LongRange implements Range<Long>, LongIterable, JetObject {
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(IntRange.class, false);
private final long start;
@@ -39,7 +39,7 @@ public final class LongRange implements Range<Long>, Iterable<Long>, JetObject {
}
@Override
public Iterator<Long> iterator() {
public LongIterator iterator() {
return new MyIterator(start, count);
}
@@ -66,7 +66,7 @@ public final class LongRange implements Range<Long>, Iterable<Long>, JetObject {
}
}
private static class MyIterator implements Iterator<Long> {
private static class MyIterator extends LongIterator {
private final static TypeInfo typeInfo = TypeInfo.getTypeInfo(MyIterator.class, false);
private long cur;
@@ -86,7 +86,7 @@ public final class LongRange implements Range<Long>, Iterable<Long>, JetObject {
}
@Override
public Long next() {
public long nextLong() {
count--;
if(reversed) {
return cur--;
+9
View File
@@ -0,0 +1,9 @@
package jet;
/**
* @author alex.tkachman
*/
public interface ShortIterable extends Iterable<Short> {
@Override
ShortIterator iterator();
}