Merge remote branch 'origin/master'
This commit is contained in:
@@ -200,7 +200,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
final JetExpression loopRange = expression.getLoopRange();
|
||||
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, loopRange);
|
||||
Type loopRangeType = typeMapper.mapType(expressionType);
|
||||
if (state.getStandardLibrary().getArray().equals(expressionType.getConstructor().getDeclarationDescriptor())) {
|
||||
if (loopRangeType.getSort() == Type.ARRAY) {
|
||||
new ForInArrayLoopGenerator(expression, loopRangeType).invoke();
|
||||
return StackValue.none();
|
||||
}
|
||||
@@ -1688,12 +1688,21 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
|
||||
private void generateNewArray(JetCallExpression expression, JetType arrayType) {
|
||||
List<? extends ValueArgument> args = expression.getValueArguments();
|
||||
if (args.size() != 1) {
|
||||
throw new CompilationException("array constructor requires one value argument");
|
||||
|
||||
boolean isArray = state.getStandardLibrary().getArray().equals(arrayType.getConstructor().getDeclarationDescriptor());
|
||||
if(isArray) {
|
||||
if (args.size() != 2 && !arrayType.getArguments().get(0).getType().isNullable()) {
|
||||
throw new CompilationException("array constructor of non-nullable type requires two arguments");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (args.size() != 1) {
|
||||
throw new CompilationException("primitive array constructor requires one argument");
|
||||
}
|
||||
}
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
|
||||
if(state.getStandardLibrary().getArray().equals(arrayType.getConstructor().getDeclarationDescriptor())) {
|
||||
if(isArray) {
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
@@ -1707,6 +1716,42 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
||||
v.newarray(type.getElementType());
|
||||
}
|
||||
|
||||
if(args.size() == 2) {
|
||||
int sizeIndex = myMap.enterTemp(2);
|
||||
int indexIndex = sizeIndex+1;
|
||||
|
||||
v.dup();
|
||||
v.arraylength();
|
||||
v.store(sizeIndex, Type.INT_TYPE);
|
||||
|
||||
v.iconst(0);
|
||||
v.store(indexIndex, Type.INT_TYPE);
|
||||
|
||||
gen(args.get(1).getArgumentExpression(), JetTypeMapper.TYPE_FUNCTION1);
|
||||
|
||||
Label begin = new Label();
|
||||
Label end = new Label();
|
||||
v.visitLabel(begin);
|
||||
v.load(indexIndex, Type.INT_TYPE);
|
||||
v.load(sizeIndex, Type.INT_TYPE);
|
||||
v.ificmpge(end);
|
||||
|
||||
v.dup2();
|
||||
v.load(indexIndex, Type.INT_TYPE);
|
||||
v.invokestatic("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
|
||||
v.invokevirtual("jet/Function1", "invoke", "(Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
v.load(indexIndex, Type.INT_TYPE);
|
||||
v.iinc(indexIndex, 1);
|
||||
v.swap();
|
||||
v.astore(JetTypeMapper.TYPE_OBJECT);
|
||||
|
||||
v.goTo(begin);
|
||||
v.visitLabel(end);
|
||||
v.pop();
|
||||
|
||||
myMap.leaveTemp(2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import jet.Function1;
|
||||
import jet.JetObject;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import jet.typeinfo.TypeInfoProjection;
|
||||
@@ -56,6 +57,7 @@ public class JetTypeMapper {
|
||||
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
|
||||
|
||||
private final HashMap<JetType,String> knowTypes = new HashMap<JetType, String>();
|
||||
public static final Type TYPE_FUNCTION1 = Type.getObjectType("jet/Function1");
|
||||
|
||||
public JetTypeMapper(JetStandardLibrary standardLibrary, BindingContext bindingContext) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
|
||||
@@ -49,7 +49,7 @@ trait Iterable<out T> {
|
||||
fun iterator() : Iterator<T>
|
||||
}
|
||||
|
||||
class Array<T>(val size : Int) {
|
||||
class Array<T>(val size : Int, init : fun(Int) : T = null ) {
|
||||
fun get(index : Int) : T
|
||||
fun set(index : Int, value : T) : Unit
|
||||
|
||||
|
||||
@@ -100,7 +100,6 @@ public interface Errors {
|
||||
DiagnosticWithParameterFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
|
||||
DiagnosticWithParameterFactory<JetProperty, JetClass> PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present", DiagnosticParameters.CLASS);
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
|
||||
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") {
|
||||
@NotNull
|
||||
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass aClass) {
|
||||
@@ -122,7 +121,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS);
|
||||
DiagnosticWithParameterFactory<JetPropertyAccessor, JetProperty> NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY = DiagnosticWithParameterFactory.create(ERROR, "Non final accessor of a final property", DiagnosticParameters.PROPERTY);
|
||||
DiagnosticWithParameterFactory<JetPropertyAccessor, JetProperty> ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY = DiagnosticWithParameterFactory.create(ERROR, "Abstract accessor of a non abstract property", DiagnosticParameters.PROPERTY);
|
||||
DiagnosticWithParameterFactory<JetPropertyAccessor, JetProperty> ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY = DiagnosticWithParameterFactory.create(ERROR, "Abstract accessor of a final property", DiagnosticParameters.PROPERTY);
|
||||
|
||||
SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
|
||||
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
|
||||
|
||||
+8
@@ -6,10 +6,18 @@ import com.intellij.psi.PsiElement;
|
||||
* @author svtk
|
||||
*/
|
||||
public class PsiElementOnlyDiagnosticFactory2<T extends PsiElement, A, B> extends DiagnosticFactoryWithPsiElement2<T, A, B> implements PsiElementOnlyDiagnosticFactory<T> {
|
||||
public static <T extends PsiElement, A, B> PsiElementOnlyDiagnosticFactory2<T, A, B> create(Severity severity, String messageStub, Renderer renderer) {
|
||||
return new PsiElementOnlyDiagnosticFactory2<T, A, B>(severity, messageStub, renderer);
|
||||
}
|
||||
|
||||
public static <T extends PsiElement, A, B> PsiElementOnlyDiagnosticFactory2<T, A, B> create(Severity severity, String messageStub) {
|
||||
return new PsiElementOnlyDiagnosticFactory2<T, A, B>(severity, messageStub);
|
||||
}
|
||||
|
||||
public PsiElementOnlyDiagnosticFactory2(Severity severity, String message, Renderer renderer) {
|
||||
super(severity, message, renderer);
|
||||
}
|
||||
|
||||
protected PsiElementOnlyDiagnosticFactory2(Severity severity, String message) {
|
||||
super(severity, message);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class DeclarationsChecker {
|
||||
return;
|
||||
}
|
||||
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on(property, abstractNode));
|
||||
context.getTrace().report(REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, abstractNode, JetTokens.ABSTRACT_KEYWORD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ public class DeclarationsChecker {
|
||||
context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(functionOrPropertyAccessor, abstractNode, functionDescriptor.getName(), classDescriptor, (JetClass) classElement));
|
||||
}
|
||||
if (hasAbstractModifier && inTrait && !isPropertyAccessor) {
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on(functionOrPropertyAccessor, abstractNode));
|
||||
context.getTrace().report(REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, abstractNode, JetTokens.ABSTRACT_KEYWORD));
|
||||
}
|
||||
if (function.getBodyExpression() != null && hasAbstractModifier) {
|
||||
context.getTrace().report(ABSTRACT_FUNCTION_WITH_BODY.on(functionOrPropertyAccessor, abstractNode, functionDescriptor));
|
||||
@@ -283,6 +283,7 @@ public class DeclarationsChecker {
|
||||
? propertyDescriptor.getGetter()
|
||||
: propertyDescriptor.getSetter();
|
||||
checkFunction(accessor, accessorDescriptor);
|
||||
checkModifiers(accessor.getModifierList());
|
||||
if (propertyDescriptor.getModality() == Modality.FINAL && accessor.hasModifier(JetTokens.OPEN_KEYWORD)) {
|
||||
ASTNode openModifierNode = accessor.getModifierList().getModifierNode(JetTokens.OPEN_KEYWORD);
|
||||
context.getTrace().report(NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY.on(accessor, openModifierNode, property));
|
||||
|
||||
Binary file not shown.
@@ -40,11 +40,6 @@ public class AddModifierFix extends ModifierFix {
|
||||
return "Add modifier";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return element.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
element.replace(addModifier(element, modifier, modifiersThanCanBeReplaced, project));
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
@@ -10,7 +15,8 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElementImpl;
|
||||
* @author svtk
|
||||
*/
|
||||
public class QuickFixUtil {
|
||||
private QuickFixUtil() {}
|
||||
private QuickFixUtil() {
|
||||
}
|
||||
|
||||
public static <T extends PsiElement, P extends T> JetIntentionActionFactory<PsiElement> createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<P> parameter) {
|
||||
return new JetIntentionActionFactory<PsiElement>() {
|
||||
@@ -18,10 +24,49 @@ public class QuickFixUtil {
|
||||
public JetIntentionAction<PsiElement> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
|
||||
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, parameter);
|
||||
T element = diagnosticWithParameters.getParameter(parameter);
|
||||
P element = diagnosticWithParameters.getParameter(parameter);
|
||||
return (JetIntentionAction<PsiElement>) factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static <T extends PsiElement, P extends T> JetIntentionActionFactory<PsiElement> createFactoryRedirectingAdditionalInfoIfAnyToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<P> parameter) {
|
||||
return new JetIntentionActionFactory<PsiElement>() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
|
||||
if (diagnostic instanceof DiagnosticWithParameters && ((DiagnosticWithParameters<PsiElement>) diagnostic).hasParameter(parameter)) {
|
||||
P element = ((DiagnosticWithParameters<PsiElement>) diagnostic).getParameter(parameter);
|
||||
return (JetIntentionAction<PsiElement>) factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
|
||||
}
|
||||
return createDoNothingAction(diagnostic);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionAction<PsiElement> createDoNothingAction(DiagnosticWithPsiElement diagnostic) {
|
||||
return new JetIntentionAction<PsiElement>(diagnostic.getPsiElement()) {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ public class QuickFixes {
|
||||
add(Errors.PROPERTY_INITIALIZER_IN_TRAIT, removePartsFromPropertyFactory);
|
||||
|
||||
add(Errors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
|
||||
add(Errors.REDUNDANT_ABSTRACT, removeAbstractModifierFactory);
|
||||
|
||||
JetIntentionActionFactory<PsiElement> addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.CLASS);
|
||||
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
|
||||
@@ -70,7 +69,7 @@ public class QuickFixes {
|
||||
add(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
add(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD));
|
||||
add(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD));
|
||||
add(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD}));
|
||||
|
||||
add(Errors.VAL_WITH_SETTER, ChangeVariableMutabilityFix.createFactory());
|
||||
|
||||
@@ -80,16 +79,16 @@ public class QuickFixes {
|
||||
JetIntentionActionFactory<JetPropertyAccessor> changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
|
||||
add(Errors.WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
|
||||
add(Errors.WRONG_GETTER_RETURN_TYPE, changeAccessorTypeFactory);
|
||||
|
||||
|
||||
add(Errors.USELESS_ELVIS, RemoveRightPartOfBinaryExpressionFix.createRemoveElvisOperatorFactory());
|
||||
|
||||
|
||||
add(Errors.UNNECESSARY_SAFE_CALL, ReplaceSafeCallToDotCall.createFactory());
|
||||
|
||||
JetIntentionActionFactory<JetModifierList> removeRedundantModifierFactory = RemoveRedundantModifierFix.createFactory();
|
||||
add(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory);
|
||||
add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory);
|
||||
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createFactory(JetTokens.FINAL_KEYWORD));
|
||||
|
||||
|
||||
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory());
|
||||
|
||||
JetIntentionActionFactory<JetClass> addPrimaryConstructorFactory = AddPrimaryConstructorFix.createFactory();
|
||||
|
||||
@@ -41,11 +41,6 @@ public class RemoveModifierFix extends ModifierFix {
|
||||
return "Remove modifier";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return element.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
|
||||
|
||||
@@ -76,11 +76,6 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
return "Remove parts from property to make it abstract";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return element.isValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetProperty newElement = (JetProperty) element.copy();
|
||||
|
||||
@@ -92,29 +92,29 @@ trait MyTrait {
|
||||
//properties
|
||||
val a: Int
|
||||
val a1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>1<!>
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val a2: Int
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val a2: Int
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
|
||||
|
||||
var b: Int private set
|
||||
var b1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; private set
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var b2: Int private set
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var b2: Int private set
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
|
||||
|
||||
var <!BACKING_FIELD_IN_TRAIT!>c<!>: Int set(v: Int) { $c = v }
|
||||
var <!BACKING_FIELD_IN_TRAIT!>c1<!>: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; set(v: Int) { $c1 = v }
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
|
||||
|
||||
val e: Int get() = a
|
||||
val e1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = a
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
|
||||
//methods
|
||||
fun f()
|
||||
fun g() {}
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> fun h()
|
||||
<!REDUNDANT_ABSTRACT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT!>abstract<!> fun h()
|
||||
<!REDUNDANT_MODIFIER_IN_TRAIT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
|
||||
|
||||
//property accessors
|
||||
var i: Int abstract get abstract set
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun box() : String {
|
||||
val a = Array<Int> (5)
|
||||
val a = Array<Int> (5, {0})
|
||||
var i = 0
|
||||
var sum = 0
|
||||
for(el in 0..4) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
fun box() : String {
|
||||
val a = IntArray (5)
|
||||
var i = 0
|
||||
var sum = 0
|
||||
for(el in 0..4) {
|
||||
a[i] = i++
|
||||
}
|
||||
for (el in a) {
|
||||
sum = sum + el
|
||||
}
|
||||
if(sum != 10) return "a failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -44,7 +44,7 @@ fun box() : String {
|
||||
}
|
||||
if(sum != 15) return "c4 failed"
|
||||
|
||||
val a : Array<Int> = Array<Int> (5)
|
||||
val a : Array<Int> = Array<Int> (5, {0})
|
||||
for(el in 0..4) {
|
||||
a[i] = i++
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ fun main(args: Array<String>?) {
|
||||
//do not compile
|
||||
System.out?.println(fff<Unit>(())) //do not compile
|
||||
System.out?.println(id<Unit>(y)) //do not compile
|
||||
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0),{(e : Int) : Unit => }))) //do not compile
|
||||
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0,{0}),{(e : Int) : Unit => }))) //do not compile
|
||||
}
|
||||
class A<T>()
|
||||
|
||||
@@ -30,7 +30,7 @@ fun almostFilter(array: Array<Int>, action: fun(Int): Int) {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a = Array<Int> (3)
|
||||
val a = Array<Int> (3,{-1})
|
||||
a[0] = 0
|
||||
a[1] = 1
|
||||
a[2] = 2
|
||||
|
||||
@@ -5,7 +5,7 @@ fun t1 () {
|
||||
}
|
||||
|
||||
fun t2 () {
|
||||
val a2 = Array<Int>(1)
|
||||
val a2 = Array<Int>(1,{0})
|
||||
a2[0] = 0 //ok
|
||||
var i = a2[0] //ok
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ fun box() : String {
|
||||
println(b.a[0])
|
||||
|
||||
val c = List<Array<Int>>(1)
|
||||
c.a[0] = Array<Int>(4)
|
||||
c.a[0] = Array<Int>(4,{-1})
|
||||
println(c.a[0].size)
|
||||
|
||||
val e = List<Int>(5)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Make 'foo' not abstract" "true"
|
||||
// "Remove redundant 'abstract' modifier" "true"
|
||||
trait A {
|
||||
<caret>fun foo()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Make 'foo' not abstract" "true"
|
||||
// "Remove redundant 'abstract' modifier" "true"
|
||||
trait A {
|
||||
<caret>abstract fun foo()
|
||||
}
|
||||
@@ -17,15 +17,24 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testCreateMultiInt () throws Exception {
|
||||
loadText("fun foo() = Array<Array<Int>> (5)");
|
||||
loadText("fun foo() = Array<Array<Int>> (5, { Array<Int>(it, {239}) })");
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof Integer[][]);
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
assertEquals(invoke[2].length, 2);
|
||||
assertEquals(invoke[4].length, 4);
|
||||
assertEquals(invoke[4][2].intValue(), 239);
|
||||
}
|
||||
|
||||
public void testCreateMultiIntNullable () throws Exception {
|
||||
loadText("fun foo() = Array<Array<Int?>> (5, { Array<Int?>(it) })");
|
||||
Method foo = generateFunction();
|
||||
Integer[][] invoke = (Integer[][]) foo.invoke(null);
|
||||
assertEquals(invoke[2].length, 2);
|
||||
assertEquals(invoke[4].length, 4);
|
||||
}
|
||||
|
||||
public void testCreateMultiString () throws Exception {
|
||||
loadText("fun foo() = Array<Array<String>> (5)");
|
||||
loadText("fun foo() = Array<Array<String>> (5, { Array<String>(0,{\"\"}) })");
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
|
||||
@@ -151,6 +151,10 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
blackBoxFile("controlStructures/forIntArray.jet");
|
||||
}
|
||||
|
||||
public void testForPrimitiveIntArray() throws Exception {
|
||||
blackBoxFile("controlStructures/forPrimitiveIntArray.jet");
|
||||
}
|
||||
|
||||
public void testForNullableIntArray() throws Exception {
|
||||
blackBoxFile("controlStructures/forNullableIntArray.jet");
|
||||
}
|
||||
|
||||
@@ -374,13 +374,24 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testArrayNew() throws Exception {
|
||||
loadText("fun foo() = Array<Int>(4)");
|
||||
loadText("fun foo() = Array<Int>(4, { it })");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
Integer[] result = (Integer[]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
assertEquals(0, result[0].intValue());
|
||||
assertEquals(1, result[1].intValue());
|
||||
assertEquals(2, result[2].intValue());
|
||||
assertEquals(3, result[3].intValue());
|
||||
}
|
||||
|
||||
public void testArrayNewNullable() throws Exception {
|
||||
loadText("fun foo() = Array<Int?>(4)");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
Integer[] result = (Integer[]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
}
|
||||
|
||||
public void testFloatArrayNew() throws Exception {
|
||||
loadText("fun foo() = FloatArray(4)");
|
||||
System.out.println(generateToText());
|
||||
@@ -390,11 +401,12 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testFloatArrayArrayNew() throws Exception {
|
||||
loadText("fun foo() = Array<FloatArray>(4)");
|
||||
loadText("fun foo() = Array<FloatArray>(4, { FloatArray(5-it) })");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
float[][] result = (float[][]) main.invoke(null);
|
||||
assertEquals(4, result.length);
|
||||
assertEquals(2, result[3].length);
|
||||
}
|
||||
|
||||
public void testArraySize() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user