Merge remote branch 'origin/master'
This commit is contained in:
@@ -36,7 +36,8 @@ public class JetControlFlowGraphTraverser<D> {
|
||||
D initialDataValueForEnterInstruction,
|
||||
boolean straightDirection) {
|
||||
initializeDataMap(pseudocode, initialDataValue);
|
||||
dataMap.put(pseudocode.getEnterInstruction(), Pair.create(initialDataValueForEnterInstruction, initialDataValueForEnterInstruction));
|
||||
dataMap.put(straightDirection ? pseudocode.getEnterInstruction() : pseudocode.getSinkInstruction(),
|
||||
Pair.create(initialDataValueForEnterInstruction, initialDataValueForEnterInstruction));
|
||||
|
||||
boolean[] changed = new boolean[1];
|
||||
changed[0] = true;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.*;
|
||||
@@ -274,7 +275,7 @@ public class JetFlowInformationProvider {
|
||||
boolean hasInitializer = !possiblePoints.isEmpty() || enterInitializationPoints.isInitialized();
|
||||
if (possiblePoints.size() == 1) {
|
||||
JetElement initializer = possiblePoints.iterator().next();
|
||||
if (initializer == element.getParent()) {
|
||||
if (initializer instanceof JetProperty && initializer == element.getParent()) {
|
||||
hasInitializer = false;
|
||||
}
|
||||
}
|
||||
@@ -402,13 +403,73 @@ public class JetFlowInformationProvider {
|
||||
for (VariableDescriptor declaredVariable : declaredVariables) {
|
||||
if (!usedVariables.contains(declaredVariable)) {
|
||||
PsiElement element = trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, declaredVariable);
|
||||
if (element instanceof JetProperty) {
|
||||
if (element instanceof JetProperty && JetPsiUtil.isLocal((JetProperty) element)) {
|
||||
PsiElement nameIdentifier = ((JetProperty) element).getNameIdentifier();
|
||||
PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : element;
|
||||
trace.report(Errors.UNUSED_VARIABLE.on((JetProperty)element, elementToMark, declaredVariable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
markUnusedValues(subroutine, pseudocode, declaredVariables);
|
||||
}
|
||||
|
||||
private void markUnusedValues(@NotNull JetElement subroutine, Pseudocode pseudocode, final Collection<VariableDescriptor> declaredVariables) {
|
||||
JetControlFlowGraphTraverser<Set<VariableDescriptor>> traverser = JetControlFlowGraphTraverser.create(pseudocode, true);
|
||||
traverser.collectInformationFromInstructionGraph(new JetControlFlowGraphTraverser.InstructionsMergeStrategy<Set<VariableDescriptor>>() {
|
||||
@Override
|
||||
public Pair<Set<VariableDescriptor>, Set<VariableDescriptor>> execute(Instruction instruction, @NotNull Collection<Set<VariableDescriptor>> incomingEdgesData) {
|
||||
Set<VariableDescriptor> enterResult = Sets.newHashSet();
|
||||
for (Set<VariableDescriptor> edgeData : incomingEdgesData) {
|
||||
enterResult.addAll(edgeData);
|
||||
}
|
||||
Set<VariableDescriptor> exitResult = Sets.newHashSet(enterResult);
|
||||
if (instruction instanceof ReadValueInstruction) {
|
||||
VariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction, true);
|
||||
if (variableDescriptor != null) {
|
||||
exitResult.add(variableDescriptor);
|
||||
}
|
||||
}
|
||||
else if (instruction instanceof WriteValueInstruction) {
|
||||
VariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction, true);
|
||||
if (variableDescriptor != null) {
|
||||
exitResult.remove(variableDescriptor);
|
||||
}
|
||||
}
|
||||
return new Pair<Set<VariableDescriptor>, Set<VariableDescriptor>>(enterResult, exitResult);
|
||||
}
|
||||
}, Collections.<VariableDescriptor>emptySet(), Collections.<VariableDescriptor>emptySet(), false);
|
||||
traverser.traverseAndAnalyzeInstructionGraph(new JetControlFlowGraphTraverser.InstructionDataAnalyzeStrategy<Set<VariableDescriptor>>() {
|
||||
@Override
|
||||
public void execute(Instruction instruction, @Nullable Set<VariableDescriptor> enterData, @Nullable Set<VariableDescriptor> exitData) {
|
||||
assert enterData != null && exitData != null;
|
||||
if (instruction instanceof WriteValueInstruction) {
|
||||
VariableDescriptor variableDescriptor = extractVariableDescriptorIfAny(instruction, false);
|
||||
if (variableDescriptor != null && declaredVariables.contains(variableDescriptor)) {
|
||||
if (!enterData.contains(variableDescriptor)) {
|
||||
PsiElement variableDeclarationElement = trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, variableDescriptor);
|
||||
assert variableDeclarationElement instanceof JetProperty || variableDeclarationElement instanceof JetParameter;
|
||||
boolean isLocal = !(variableDeclarationElement instanceof JetProperty) || JetPsiUtil.isLocal((JetProperty) variableDeclarationElement);
|
||||
if (isLocal) {
|
||||
JetElement element = ((WriteValueInstruction) instruction).getElement();
|
||||
if (element instanceof JetBinaryExpression && ((JetBinaryExpression) element).getOperationToken() == JetTokens.EQ) {
|
||||
JetExpression right = ((JetBinaryExpression) element).getRight();
|
||||
if (right != null) {
|
||||
trace.report(Errors.UNUSED_VALUE.on(right, right, variableDescriptor));
|
||||
}
|
||||
}
|
||||
else if (element instanceof JetPostfixExpression) {
|
||||
IElementType operationToken = ((JetPostfixExpression) element).getOperationSign().getReferencedNameElementType();
|
||||
if (operationToken == JetTokens.PLUSPLUS || operationToken == JetTokens.MINUSMINUS) {
|
||||
trace.report(Errors.UNUSED_CHANGED_VALUE.on(element, element));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
@@ -25,9 +24,6 @@ public interface CallableDescriptor extends DeclarationDescriptor {
|
||||
@NotNull
|
||||
JetType getReturnType();
|
||||
|
||||
@Nullable
|
||||
JetType getReturnTypeSafe();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
CallableDescriptor getOriginal();
|
||||
|
||||
@@ -125,12 +125,6 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
||||
return unsubstitutedReturnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetType getReturnTypeSafe() {
|
||||
return unsubstitutedReturnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor getOriginal() {
|
||||
|
||||
+14
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
@@ -7,6 +8,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -95,4 +97,16 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
public PropertyAccessorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
throw new UnsupportedOperationException("Accessors must be copied by the corresponding property");
|
||||
}
|
||||
|
||||
protected Set<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) {
|
||||
Set<? extends PropertyDescriptor> overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors();
|
||||
Set<PropertyAccessorDescriptor> overriddenAccessors = Sets.newHashSet();
|
||||
for (PropertyDescriptor overriddenProperty : overriddenProperties) {
|
||||
PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter();
|
||||
if (accessorDescriptor != null) {
|
||||
overriddenAccessors.add(accessorDescriptor);
|
||||
}
|
||||
}
|
||||
return overriddenAccessors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
private final ReceiverDescriptor receiver;
|
||||
private final ReceiverDescriptor expectedThisObject;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet();
|
||||
private final Set<PropertyDescriptor> overridingProperties = Sets.newLinkedHashSet();
|
||||
private final List<TypeParameterDescriptor> typeParemeters = Lists.newArrayListWithCapacity(0);
|
||||
private final PropertyDescriptor original;
|
||||
private PropertyGetterDescriptor getter;
|
||||
@@ -118,11 +119,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
return getOutType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetType getReturnTypeSafe() {
|
||||
return getOutType();
|
||||
}
|
||||
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
@@ -195,7 +191,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@Override
|
||||
public Set<? extends PropertyDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenProperties;
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -217,7 +212,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
||||
propertyDescriptor,
|
||||
Lists.newArrayList(setter.getAnnotations()),
|
||||
setter.hasBody(), setter.isDefault());;
|
||||
setter.hasBody(), setter.isDefault());
|
||||
propertyDescriptor.initialize(DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), newGetter, newSetter);
|
||||
return propertyDescriptor;
|
||||
}
|
||||
|
||||
+2
-13
@@ -15,7 +15,6 @@ import java.util.Set;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
|
||||
private JetType returnType;
|
||||
|
||||
public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @NotNull Modality modality, @NotNull Visibility visibility, @Nullable JetType returnType, boolean hasBody, boolean isDefault) {
|
||||
@@ -25,12 +24,8 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends FunctionDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenGetters;
|
||||
}
|
||||
|
||||
public void addOverriddenFunction(@NotNull PropertyGetterDescriptor overriddenGetter) {
|
||||
overriddenGetters.add(overriddenGetter);
|
||||
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
|
||||
return super.getOverriddenDescriptors(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -45,12 +40,6 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetType getReturnTypeSafe() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertyGetterDescriptor(this, data);
|
||||
|
||||
+2
-12
@@ -16,7 +16,6 @@ import java.util.Set;
|
||||
public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
|
||||
private MutableValueParameterDescriptor parameter;
|
||||
private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet();
|
||||
|
||||
public PropertySetterDescriptor(@NotNull Modality modality, @NotNull Visibility visibility, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, boolean hasBody, boolean isDefault) {
|
||||
super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||
@@ -33,12 +32,8 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends FunctionDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenSetters;
|
||||
}
|
||||
|
||||
public void setOverriddenFunction(@NotNull PropertySetterDescriptor overriddenSetter) {
|
||||
overriddenSetters.add(overriddenSetter);
|
||||
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
|
||||
return super.getOverriddenDescriptors(false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -53,11 +48,6 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
return JetStandardClasses.getUnitType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getReturnTypeSafe() {
|
||||
return getReturnType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertySetterDescriptor(this, data);
|
||||
|
||||
@@ -89,10 +89,4 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
public JetType getReturnType() {
|
||||
return getOutType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetType getReturnTypeSafe() {
|
||||
return getOutType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,19 @@ public interface Errors {
|
||||
|
||||
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
|
||||
PsiElementOnlyDiagnosticFactory1<JetProperty, DeclarationDescriptor> UNUSED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(WARNING, "Variable ''{0}'' is never used", NAME);
|
||||
PsiElementOnlyDiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = new PsiElementOnlyDiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor>(WARNING, "The value ''{0}'' assigned to ''{1}'' is never used", NAME) {
|
||||
@Override
|
||||
protected String makeMessageForA(@NotNull JetElement element) {
|
||||
return element.getText();
|
||||
}
|
||||
};
|
||||
PsiElementOnlyDiagnosticFactory1<JetElement, JetElement> UNUSED_CHANGED_VALUE = new PsiElementOnlyDiagnosticFactory1<JetElement, JetElement>(WARNING, "The value changed at ''{0}'' is never used", NAME) {
|
||||
@Override
|
||||
protected String makeMessageFor(JetElement argument) {
|
||||
return argument.getText();
|
||||
}
|
||||
};
|
||||
|
||||
PsiElementOnlyDiagnosticFactory2<JetExpression, DeclarationDescriptor, JetProperty[]> VAL_REASSIGNMENT = new PsiElementOnlyDiagnosticFactory2<JetExpression, DeclarationDescriptor, JetProperty[]>(ERROR, "Val can not be reassigned", NAME) {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -102,4 +103,17 @@ public class JetPsiUtil {
|
||||
return unquoteIdentifier(quoted);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLocal(@NotNull JetProperty property) {
|
||||
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(property, JetClassOrObject.class);
|
||||
JetDeclarationWithBody function = PsiTreeUtil.getParentOfType(property, JetDeclarationWithBody.class);
|
||||
if (function != null && PsiTreeUtil.isAncestor(classOrObject, function, false)) {
|
||||
return true;
|
||||
}
|
||||
if (classOrObject != null && PsiTreeUtil.isAncestor(function, classOrObject, false)) {
|
||||
return false;
|
||||
}
|
||||
if (function != null) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,6 @@ public class ControlFlowAnalyzer {
|
||||
|
||||
flowInformationProvider.markUninitializedVariables(function.asElement(), false, inLocalDeclaration);
|
||||
|
||||
// flowInformationProvider.markUnusedVariables(function.asElement());
|
||||
flowInformationProvider.markUnusedVariables(function.asElement());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,16 +110,17 @@ public class OverrideResolver {
|
||||
Set<CallableMemberDescriptor> manyImpl = Sets.newLinkedHashSet();
|
||||
collectMissingImplementations(classDescriptor, abstractNoImpl, manyImpl);
|
||||
|
||||
PsiElement nameIdentifier = klass;
|
||||
PsiElement nameIdentifier = null;
|
||||
if (klass instanceof JetClass) {
|
||||
nameIdentifier = ((JetClass) klass).getNameIdentifier();
|
||||
}
|
||||
else if (klass instanceof JetObjectDeclaration) {
|
||||
nameIdentifier = ((JetObjectDeclaration) klass).getNameIdentifier();
|
||||
}
|
||||
PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : klass;
|
||||
|
||||
for (CallableMemberDescriptor memberDescriptor : manyImpl) {
|
||||
context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
|
||||
context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(elementToMark, klass, memberDescriptor));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) {
|
||||
context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
|
||||
context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(elementToMark, klass, memberDescriptor));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,11 +73,7 @@ public class DescriptorRenderer implements Renderer {
|
||||
}
|
||||
|
||||
public String renderType(JetType type) {
|
||||
if (type == null) {
|
||||
return escape("<?>");
|
||||
} else {
|
||||
return escape(type.toString());
|
||||
}
|
||||
return escape(type.toString());
|
||||
}
|
||||
|
||||
protected String escape(String s) {
|
||||
@@ -226,7 +222,8 @@ public class DescriptorRenderer implements Renderer {
|
||||
|
||||
renderName(descriptor, builder);
|
||||
renderValueParameters(descriptor, builder);
|
||||
builder.append(" : ").append(escape(renderType(descriptor.getReturnTypeSafe())));
|
||||
// TODO: getReturnType may be uninitialized and throw IllegalStateException // stepan.koltsov@ 2011-11-21
|
||||
builder.append(" : ").append(escape(renderType(descriptor.getReturnType())));
|
||||
return super.visitFunctionDescriptor(descriptor, builder);
|
||||
}
|
||||
|
||||
|
||||
@@ -236,6 +236,6 @@ abstract class B3(i: Int) {
|
||||
}
|
||||
|
||||
fun foo(a: B3) {
|
||||
val a = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
|
||||
val b = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
|
||||
val <!UNUSED_VARIABLE!>a<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
|
||||
val <!UNUSED_VARIABLE!>b<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class WithC() {
|
||||
}
|
||||
|
||||
this(a : Int) : this() {
|
||||
val b = x
|
||||
val <!UNUSED_VARIABLE!>b<!> = x
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ fun A.plus(a : Int) {
|
||||
fun <T> T.minus(t : T) : Int = 1
|
||||
|
||||
fun test() {
|
||||
val y = 1.abs
|
||||
val <!UNUSED_VARIABLE!>y<!> = 1.abs
|
||||
}
|
||||
val Int.abs : Int
|
||||
get() = if (this > 0) this else -this;
|
||||
|
||||
@@ -116,7 +116,7 @@ fun blockReturnValueTypeMatch12() : Int {
|
||||
else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!>
|
||||
}
|
||||
fun blockNoReturnIfValDeclaration(): Int {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val x = 1<!>
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val <!UNUSED_VARIABLE!>x<!> = 1<!>
|
||||
}
|
||||
fun blockNoReturnIfEmptyIf(): Int {
|
||||
if (1 < 2) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
@@ -174,37 +174,37 @@ class B() {
|
||||
}
|
||||
|
||||
fun testFunctionLiterals() {
|
||||
val endsWithVarDeclaration : fun() : Boolean = {
|
||||
val <!UNUSED_VARIABLE!>endsWithVarDeclaration<!> : fun() : Boolean = {
|
||||
<!EXPECTED_TYPE_MISMATCH!>val x = 2<!>
|
||||
}
|
||||
|
||||
val endsWithAssignment = { () : Int =>
|
||||
val <!UNUSED_VARIABLE!>endsWithAssignment<!> = { () : Int =>
|
||||
var x = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x = 333<!>
|
||||
}
|
||||
|
||||
val endsWithReAssignment = { () : Int =>
|
||||
val <!UNUSED_VARIABLE!>endsWithReAssignment<!> = { () : Int =>
|
||||
var x = 1
|
||||
<!ASSIGNMENT_TYPE_MISMATCH!>x += 333<!>
|
||||
}
|
||||
|
||||
val endsWithFunDeclaration : fun() : String = {
|
||||
val <!UNUSED_VARIABLE!>endsWithFunDeclaration<!> : fun() : String = {
|
||||
var x = 1
|
||||
x = 333
|
||||
<!EXPECTED_TYPE_MISMATCH!>fun meow() : Unit {}<!>
|
||||
}
|
||||
|
||||
val endsWithObjectDeclaration : fun() : Int = {
|
||||
val <!UNUSED_VARIABLE!>endsWithObjectDeclaration<!> : fun() : Int = {
|
||||
var x = 1
|
||||
x = 333
|
||||
<!EXPECTED_TYPE_MISMATCH!>object A {}<!>
|
||||
}
|
||||
|
||||
val expectedUnitReturnType1 = { () : Unit =>
|
||||
val <!UNUSED_VARIABLE!>expectedUnitReturnType1<!> = { () : Unit =>
|
||||
val x = 1
|
||||
}
|
||||
|
||||
val expectedUnitReturnType2 = { () : Unit =>
|
||||
val <!UNUSED_VARIABLE!>expectedUnitReturnType2<!> = { () : Unit =>
|
||||
fun meow() : Unit {}
|
||||
object A {}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ fun testIncDec() {
|
||||
++x
|
||||
x--
|
||||
--x
|
||||
x = x++
|
||||
x = x--
|
||||
x = <!UNUSED_CHANGED_VALUE!>x++<!>
|
||||
x = <!UNUSED_CHANGED_VALUE!>x--<!>
|
||||
x = ++x
|
||||
x = --x
|
||||
x = <!UNUSED_VALUE!>--x<!>
|
||||
}
|
||||
|
||||
class WrongIncDec() {
|
||||
@@ -39,8 +39,8 @@ fun testUnitIncDec() {
|
||||
++x
|
||||
x--
|
||||
--x
|
||||
x = <!TYPE_MISMATCH!>x++<!>
|
||||
x = <!TYPE_MISMATCH!>x--<!>
|
||||
x = <!TYPE_MISMATCH, UNUSED_CHANGED_VALUE!>x++<!>
|
||||
x = <!TYPE_MISMATCH, UNUSED_CHANGED_VALUE!>x--<!>
|
||||
x = <!TYPE_MISMATCH!>++x<!>
|
||||
x = <!TYPE_MISMATCH!>--x<!>
|
||||
x = <!TYPE_MISMATCH, UNUSED_VALUE!>--x<!>
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace qualified_expressions
|
||||
|
||||
fun test(s: String?) {
|
||||
val a: Int = <!TYPE_MISMATCH!>s?.length<!>
|
||||
val <!UNUSED_VARIABLE!>a<!>: Int = <!TYPE_MISMATCH!>s?.length<!>
|
||||
val b: Int? = s?.length
|
||||
val c: Int = s?.length ?: -11
|
||||
val d: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!>
|
||||
val <!UNUSED_VARIABLE!>c<!>: Int = s?.length ?: -11
|
||||
val <!UNUSED_VARIABLE!>d<!>: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!>
|
||||
val e: String = <!TYPE_MISMATCH!>s?.length<!> ?: "empty"
|
||||
val f: Int = s?.length ?: b ?: 1
|
||||
val g: Int? = e? startsWith("s")?.length
|
||||
val <!UNUSED_VARIABLE!>f<!>: Int = s?.length ?: b ?: 1
|
||||
val <!UNUSED_VARIABLE!>g<!>: Int? = e? startsWith("s")?.length
|
||||
}
|
||||
@@ -31,11 +31,11 @@ namespace closures {
|
||||
val Int.xx = this : Int
|
||||
fun Char.xx() : Any {
|
||||
this : Char
|
||||
val a = {Double.() => this : Double + this@xx : Char}
|
||||
val b = @a{Double.() => this@a : Double + this@xx : Char}
|
||||
val c = @a{() => <!NO_THIS!>this@a<!> + this@xx : Char}
|
||||
val <!UNUSED_VARIABLE!>a<!> = {Double.() => this : Double + this@xx : Char}
|
||||
val <!UNUSED_VARIABLE!>b<!> = @a{Double.() => this@a : Double + this@xx : Char}
|
||||
val <!UNUSED_VARIABLE!>c<!> = @a{() => <!NO_THIS!>this@a<!> + this@xx : Char}
|
||||
return (@a{Double.() => this@a : Double + this@xx : Char})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import java.lang.Comparable as Com
|
||||
val l : List<in Int> = ArrayList<Int>()
|
||||
|
||||
fun test(l : java.util.List<Int>) {
|
||||
val x : java.<!UNRESOLVED_REFERENCE!>List<!>
|
||||
val y : java.util.List<Int>
|
||||
val b : java.lang.Object
|
||||
val a : util.List<Int>
|
||||
val z : java.<!UNRESOLVED_REFERENCE!>utils<!>.List<Int>
|
||||
val <!UNUSED_VARIABLE!>x<!> : java.<!UNRESOLVED_REFERENCE!>List<!>
|
||||
val <!UNUSED_VARIABLE!>y<!> : java.util.List<Int>
|
||||
val <!UNUSED_VARIABLE!>b<!> : java.lang.Object
|
||||
val <!UNUSED_VARIABLE!>a<!> : util.List<Int>
|
||||
val <!UNUSED_VARIABLE!>z<!> : java.<!UNRESOLVED_REFERENCE!>utils<!>.List<Int>
|
||||
|
||||
val f : java.io.File? = null
|
||||
val <!UNUSED_VARIABLE!>f<!> : java.io.File? = null
|
||||
|
||||
Collections.<!UNRESOLVED_REFERENCE!>emptyList<!>
|
||||
Collections.emptyList<Int>
|
||||
@@ -27,7 +27,7 @@ fun test(l : java.util.List<Int>) {
|
||||
<!UNRESOLVED_REFERENCE!>List<!><Int>
|
||||
|
||||
|
||||
val o = "sdf" <!CAST_NEVER_SUCCEEDS!>as<!> Object
|
||||
val <!UNUSED_VARIABLE!>o<!> = "sdf" <!CAST_NEVER_SUCCEEDS!>as<!> Object
|
||||
|
||||
try {
|
||||
// ...
|
||||
@@ -49,4 +49,4 @@ fun test(l : java.util.List<Int>) {
|
||||
|
||||
namespace xxx {
|
||||
import java.lang.Class;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace unresolved
|
||||
|
||||
fun testGenericArgumentsCount() {
|
||||
val p1: Tuple2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = (2, 2)
|
||||
val p2: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Tuple2<!> = (2, 2)
|
||||
val <!UNUSED_VARIABLE!>p1<!>: Tuple2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = (2, 2)
|
||||
val <!UNUSED_VARIABLE!>p2<!>: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Tuple2<!> = (2, 2)
|
||||
}
|
||||
|
||||
fun testUnresolved() {
|
||||
if (<!UNRESOLVED_REFERENCE!>a<!> is String) {
|
||||
val s = <!UNRESOLVED_REFERENCE!>a<!>
|
||||
val <!UNUSED_VARIABLE!>s<!> = <!UNRESOLVED_REFERENCE!>a<!>
|
||||
}
|
||||
<!UNRESOLVED_REFERENCE!>foo<!>(<!UNRESOLVED_REFERENCE!>a<!>)
|
||||
val s = "s"
|
||||
@@ -28,4 +28,4 @@ fun testUnresolved() {
|
||||
}
|
||||
}
|
||||
|
||||
fun foo1(i: Int) {}
|
||||
fun foo1(i: Int) {}
|
||||
@@ -8,13 +8,13 @@ abstract class Usual<T> {}
|
||||
|
||||
fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
|
||||
val c1: Consumer<Any> = <!TYPE_MISMATCH!>c<!>
|
||||
val c2: Consumer<Int> = c1
|
||||
val <!UNUSED_VARIABLE!>c2<!>: Consumer<Int> = c1
|
||||
|
||||
val p1: Producer<Any> = p
|
||||
val p2: Producer<Int> = <!TYPE_MISMATCH!>p1<!>
|
||||
val <!UNUSED_VARIABLE!>p2<!>: Producer<Int> = <!TYPE_MISMATCH!>p1<!>
|
||||
|
||||
val u1: Usual<Any> = <!TYPE_MISMATCH!>u<!>
|
||||
val u2: Usual<Int> = <!TYPE_MISMATCH!>u1<!>
|
||||
val <!UNUSED_VARIABLE!>u2<!>: Usual<Int> = <!TYPE_MISMATCH!>u1<!>
|
||||
}
|
||||
|
||||
//Arrays copy example
|
||||
@@ -37,4 +37,4 @@ fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) {
|
||||
copy2(ints, <!TYPE_MISMATCH!>numbers<!>)
|
||||
copy3<Int>(ints, numbers)
|
||||
copy4(ints, numbers) //ok
|
||||
}
|
||||
}
|
||||
@@ -165,42 +165,42 @@ fun illegalWhenBlock(a: Any): Int {
|
||||
}
|
||||
fun declarations(a: Any?) {
|
||||
if (a is String) {
|
||||
val p4: (Int, String) = (2, a)
|
||||
val <!UNUSED_VARIABLE!>p4<!>: (Int, String) = (2, a)
|
||||
}
|
||||
if (a is String?) {
|
||||
if (a != null) {
|
||||
val s: String = a
|
||||
val <!UNUSED_VARIABLE!>s<!>: String = a
|
||||
}
|
||||
}
|
||||
if (a != null) {
|
||||
if (a is String?) {
|
||||
val s: String = a
|
||||
val <!UNUSED_VARIABLE!>s<!>: String = a
|
||||
}
|
||||
}
|
||||
}
|
||||
fun vars(a: Any?) {
|
||||
var b: Int = 0
|
||||
var <!UNUSED_VARIABLE!>b<!>: Int = 0
|
||||
if (a is Int) {
|
||||
b = a
|
||||
b = <!UNUSED_VALUE!>a<!>
|
||||
}
|
||||
}
|
||||
fun tuples(a: Any?) {
|
||||
if (a != null) {
|
||||
val s: (Any, String) = (a, <!TYPE_MISMATCH!>a<!>)
|
||||
val <!UNUSED_VARIABLE!>s<!>: (Any, String) = (a, <!TYPE_MISMATCH!>a<!>)
|
||||
}
|
||||
if (a is String) {
|
||||
val s: (Any, String) = (a, a)
|
||||
val <!UNUSED_VARIABLE!>s<!>: (Any, String) = (a, a)
|
||||
}
|
||||
fun illegalTupleReturnType(): (Any, String) = (<!TYPE_MISMATCH!>a<!>, <!TYPE_MISMATCH!>a<!>)
|
||||
if (a is String) {
|
||||
fun legalTupleReturnType(): (Any, String) = (a, a)
|
||||
}
|
||||
val illegalFunctionLiteral: Function0<Int> = <!TYPE_MISMATCH!>{ <!TYPE_MISMATCH!>a<!> }<!>
|
||||
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <!TYPE_MISMATCH!>a<!> }
|
||||
val <!UNUSED_VARIABLE!>illegalFunctionLiteral<!>: Function0<Int> = <!TYPE_MISMATCH!>{ <!TYPE_MISMATCH!>a<!> }<!>
|
||||
val <!UNUSED_VARIABLE!>illegalReturnValueInFunctionLiteral<!>: Function0<Int> = { (): Int => <!TYPE_MISMATCH!>a<!> }
|
||||
|
||||
if (a is Int) {
|
||||
val legalFunctionLiteral: Function0<Int> = { a }
|
||||
val alsoLegalFunctionLiteral: Function0<Int> = { (): Int => a }
|
||||
val <!UNUSED_VARIABLE!>legalFunctionLiteral<!>: Function0<Int> = { a }
|
||||
val <!UNUSED_VARIABLE!>alsoLegalFunctionLiteral<!>: Function0<Int> = { (): Int => a }
|
||||
}
|
||||
}
|
||||
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
|
||||
@@ -227,7 +227,7 @@ fun mergeAutocasts(a: Any?) {
|
||||
is String, is Any => a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
|
||||
}
|
||||
if (a is String && a is Any) {
|
||||
val i: Int = a.compareTo("")
|
||||
val <!UNUSED_VARIABLE!>i<!>: Int = a.compareTo("")
|
||||
}
|
||||
if (a is String && a.compareTo("") == 0) {}
|
||||
if (a is String || a.<!UNRESOLVED_REFERENCE!>compareTo<!>("") == 0) {}
|
||||
@@ -237,9 +237,9 @@ fun mergeAutocasts(a: Any?) {
|
||||
fun f(): String {
|
||||
var a: Any = 11
|
||||
if (a is String) {
|
||||
val i: String = <!AUTOCAST_IMPOSSIBLE!>a<!>
|
||||
val <!UNUSED_VARIABLE!>i<!>: String = <!AUTOCAST_IMPOSSIBLE!>a<!>
|
||||
<!AUTOCAST_IMPOSSIBLE!>a<!>.compareTo("f")
|
||||
val f: Function0<String> = { <!AUTOCAST_IMPOSSIBLE!>a<!> }
|
||||
val <!UNUSED_VARIABLE!>f<!>: Function0<String> = { <!AUTOCAST_IMPOSSIBLE!>a<!> }
|
||||
return <!AUTOCAST_IMPOSSIBLE!>a<!>
|
||||
}
|
||||
return ""
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@ fun test() {
|
||||
var a : Any? = null
|
||||
if (a is Any) else a = null;
|
||||
while (a is Any) a = null
|
||||
while (true) a = null
|
||||
while (true) a = <!UNUSED_VALUE!>null<!>
|
||||
}
|
||||
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
|
||||
|
||||
fun test() : Int {
|
||||
foo(<!TYPE_MISMATCH!>1<!>)
|
||||
val a : fun() : Unit = {
|
||||
val <!UNUSED_VARIABLE!>a<!> : fun() : Unit = {
|
||||
foo(<!TYPE_MISMATCH!>1<!>)
|
||||
}
|
||||
return 1
|
||||
|
||||
@@ -32,7 +32,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||
fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||
val lhs = evaluateAdd(expr, numbers)
|
||||
if (expr.length() > 0) {
|
||||
val c = expr.charAt(0)
|
||||
val <!UNUSED_VARIABLE!>c<!> = expr.charAt(0)
|
||||
expr.deleteCharAt(0)
|
||||
}
|
||||
return lhs
|
||||
@@ -63,4 +63,4 @@ fun main(args: Array<String>) {
|
||||
catch(e: Throwable) {
|
||||
System.out?.println(e.getMessage())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
fun foo1() : fun (Int) : Int = { (x: Int) => x }
|
||||
|
||||
fun foo() {
|
||||
val h : fun (Int) : Int = foo1();
|
||||
val <!UNUSED_VARIABLE!>h<!> : fun (Int) : Int = foo1();
|
||||
h(1)
|
||||
val m : fun (Int) : Int = {(a : Int) => 1}//foo1()
|
||||
val <!UNUSED_VARIABLE!>m<!> : fun (Int) : Int = {(a : Int) => 1}//foo1()
|
||||
m(1)
|
||||
}
|
||||
@@ -18,5 +18,5 @@ enum class Foo<T> {
|
||||
|
||||
|
||||
fun box() {
|
||||
val x: ProtocolState = ProtocolState.WAITING
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>x<!>: ProtocolState = ProtocolState.WAITING
|
||||
}
|
||||
+3
-4
@@ -1,4 +1,4 @@
|
||||
class Foo(var bar : Int, var barr : Int, var barrr : Int) {
|
||||
class Foo(var bar : Int, var barr : Int, var barrr : Int) {
|
||||
{
|
||||
bar = 1
|
||||
barr = 1
|
||||
@@ -11,8 +11,7 @@
|
||||
bar = 1
|
||||
this.bar
|
||||
1 : Int
|
||||
val a : Int =1
|
||||
val <!UNUSED_VARIABLE!>a<!> : Int =1
|
||||
this : Foo
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,42 +17,42 @@ class AClass() {
|
||||
val x : Any? = 1
|
||||
|
||||
fun Any?.vars(a: Any?) : Int {
|
||||
var b: Int = 0
|
||||
var <!UNUSED_VARIABLE!>b<!>: Int = 0
|
||||
if (ns.y is Int) {
|
||||
b = ns.y
|
||||
b = <!UNUSED_VALUE!>ns.y<!>
|
||||
}
|
||||
if (ns.y is Int) {
|
||||
b = example.ns.y
|
||||
b = <!UNUSED_VALUE!>example.ns.y<!>
|
||||
}
|
||||
if (example.ns.y is Int) {
|
||||
b = ns.y
|
||||
b = <!UNUSED_VALUE!>ns.y<!>
|
||||
}
|
||||
if (example.ns.y is Int) {
|
||||
b = example.ns.y
|
||||
b = <!UNUSED_VALUE!>example.ns.y<!>
|
||||
}
|
||||
// if (namespace.bottles.ns.y is Int) {
|
||||
// b = ns.y
|
||||
// }
|
||||
if (Obj.y is Int) {
|
||||
b = Obj.y
|
||||
b = <!UNUSED_VALUE!>Obj.y<!>
|
||||
}
|
||||
if (example.Obj.y is Int) {
|
||||
b = Obj.y
|
||||
b = <!UNUSED_VALUE!>Obj.y<!>
|
||||
}
|
||||
if (AClass.y is Int) {
|
||||
b = AClass.y
|
||||
b = <!UNUSED_VALUE!>AClass.y<!>
|
||||
}
|
||||
if (example.AClass.y is Int) {
|
||||
b = AClass.y
|
||||
b = <!UNUSED_VALUE!>AClass.y<!>
|
||||
}
|
||||
if (x is Int) {
|
||||
b = x
|
||||
b = <!UNUSED_VALUE!>x<!>
|
||||
}
|
||||
if (example.x is Int) {
|
||||
b = x
|
||||
b = <!UNUSED_VALUE!>x<!>
|
||||
}
|
||||
if (example.x is Int) {
|
||||
b = example.x
|
||||
b = <!UNUSED_VALUE!>example.x<!>
|
||||
}
|
||||
return 1
|
||||
}
|
||||
@@ -74,18 +74,18 @@ trait T {}
|
||||
|
||||
open class C {
|
||||
fun foo() {
|
||||
var t : T? = null
|
||||
var <!UNUSED_VARIABLE!>t<!> : T? = null
|
||||
if (this is T) {
|
||||
t = this
|
||||
t = <!UNUSED_VALUE!>this<!>
|
||||
}
|
||||
if (this is T) {
|
||||
t = this@C
|
||||
t = <!UNUSED_VALUE!>this@C<!>
|
||||
}
|
||||
if (this@C is T) {
|
||||
t = this
|
||||
t = <!UNUSED_VALUE!>this<!>
|
||||
}
|
||||
if (this@C is T) {
|
||||
t = this@C
|
||||
t = <!UNUSED_VALUE!>this@C<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
|
||||
|
||||
fun test() : Int {
|
||||
foo(<!TYPE_MISMATCH!>1<!>)
|
||||
val a : fun() : Unit = {
|
||||
val <!UNUSED_VARIABLE!>a<!> : fun() : Unit = {
|
||||
foo(<!TYPE_MISMATCH!>1<!>)
|
||||
}
|
||||
return 1 <!NONE_APPLICABLE!>-<!> "1"
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// KT-451 Incorrect character literals cause assertion failures
|
||||
|
||||
fun ff() {
|
||||
val b = <!ERROR_COMPILE_TIME_VALUE!>''<!>
|
||||
val c = <!ERROR_COMPILE_TIME_VALUE!>'23'<!>
|
||||
val d = <!ERROR_COMPILE_TIME_VALUE!>'a<!>
|
||||
val e = <!ERROR_COMPILE_TIME_VALUE!>'ab<!>
|
||||
val f = <!ERROR_COMPILE_TIME_VALUE!>'\'<!>
|
||||
val <!UNUSED_VARIABLE!>b<!> = <!ERROR_COMPILE_TIME_VALUE!>''<!>
|
||||
val <!UNUSED_VARIABLE!>c<!> = <!ERROR_COMPILE_TIME_VALUE!>'23'<!>
|
||||
val <!UNUSED_VARIABLE!>d<!> = <!ERROR_COMPILE_TIME_VALUE!>'a<!>
|
||||
val <!UNUSED_VARIABLE!>e<!> = <!ERROR_COMPILE_TIME_VALUE!>'ab<!>
|
||||
val <!UNUSED_VARIABLE!>f<!> = <!ERROR_COMPILE_TIME_VALUE!>'\'<!>
|
||||
}
|
||||
|
||||
fun test() {
|
||||
@@ -34,5 +34,4 @@ fun test() {
|
||||
<!ERROR_COMPILE_TIME_VALUE!>'\u000z'<!>
|
||||
<!ERROR_COMPILE_TIME_VALUE!>'\\u000'<!>
|
||||
<!ERROR_COMPILE_TIME_VALUE!>'\'<!>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
fun ff() {
|
||||
val i: Int = 1
|
||||
val a: Int = i<!UNNECESSARY_SAFE_CALL!>?.<!>plus(2)
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>a<!>: Int = i<!UNNECESSARY_SAFE_CALL!>?.<!>plus(2)
|
||||
}
|
||||
@@ -2,5 +2,5 @@ fun Int.gg() = null
|
||||
|
||||
fun ff() {
|
||||
val a: Int = 1
|
||||
val b: Int = <!TYPE_MISMATCH!>a<!UNNECESSARY_SAFE_CALL!>?.<!>gg()<!>
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>b<!>: Int = <!TYPE_MISMATCH!>a<!UNNECESSARY_SAFE_CALL!>?.<!>gg()<!>
|
||||
}
|
||||
@@ -5,7 +5,7 @@ fun any(a : Any) {}
|
||||
fun notAnExpression() {
|
||||
any(<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>) // not an expression
|
||||
if (<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>) {} else {} // not an expression
|
||||
val x = <!SUPER_IS_NOT_AN_EXPRESSION!>super<!> // not an expression
|
||||
val <!UNUSED_VARIABLE!>x<!> = <!SUPER_IS_NOT_AN_EXPRESSION!>super<!> // not an expression
|
||||
when (1) {
|
||||
<!SUPER_IS_NOT_AN_EXPRESSION!>super<!> => 1 // not an expression
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ fun foo(c: C<Int>) {}
|
||||
fun bar<T>() : C<T> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val a : C<Int> = C();
|
||||
val x : C<in String> = C()
|
||||
val y : C<out String> = C()
|
||||
val z : C<*> = C()
|
||||
val <!UNUSED_VARIABLE!>a<!> : C<Int> = C();
|
||||
val <!UNUSED_VARIABLE!>x<!> : C<in String> = C()
|
||||
val <!UNUSED_VARIABLE!>y<!> : C<out String> = C()
|
||||
val <!UNUSED_VARIABLE!>z<!> : C<*> = C()
|
||||
|
||||
val ba : C<Int> = bar();
|
||||
val bx : C<in String> = bar()
|
||||
val by : C<out String> = bar()
|
||||
val bz : C<*> = bar()
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>ba<!> : C<Int> = bar();
|
||||
val <!UNUSED_VARIABLE!>bx<!> : C<in String> = bar()
|
||||
val <!UNUSED_VARIABLE!>by<!> : C<out String> = bar()
|
||||
val <!UNUSED_VARIABLE!>bz<!> : C<*> = bar()
|
||||
}
|
||||
+10
-10
@@ -63,11 +63,11 @@ fun t4(a: A, val b: A, var c: A) {
|
||||
// reassigned vals
|
||||
|
||||
fun t1() {
|
||||
val a : Int = 1
|
||||
<!VAL_REASSIGNMENT!>a<!> = 2
|
||||
val <!UNUSED_VARIABLE!>a<!> : Int = 1
|
||||
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>2<!>
|
||||
|
||||
var b : Int = 1
|
||||
b = 3
|
||||
var <!UNUSED_VARIABLE!>b<!> : Int = 1
|
||||
b = <!UNUSED_VALUE!>3<!>
|
||||
}
|
||||
|
||||
abstract enum class ProtocolState {
|
||||
@@ -85,7 +85,7 @@ abstract enum class ProtocolState {
|
||||
fun t3() {
|
||||
val x: ProtocolState = ProtocolState.WAITING
|
||||
<!VAL_REASSIGNMENT!>x<!> = x.signal()
|
||||
x = x.signal() //repeat for x
|
||||
x = <!UNUSED_VALUE!>x.signal()<!> //repeat for x
|
||||
}
|
||||
|
||||
fun t4() {
|
||||
@@ -265,7 +265,7 @@ class ClassObject() {
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
val a = object {
|
||||
val <!UNUSED_VARIABLE!>a<!> = object {
|
||||
val x : Int
|
||||
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>y<!> : Int
|
||||
val z : Int
|
||||
@@ -283,7 +283,7 @@ fun foo() {
|
||||
class TestObjectExpression() {
|
||||
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>a<!> : Int
|
||||
fun foo() {
|
||||
val a = object {
|
||||
val <!UNUSED_VARIABLE!>a<!> = object {
|
||||
val x : Int
|
||||
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>y<!> : Int
|
||||
{
|
||||
@@ -325,10 +325,10 @@ object TestObjectDeclaration {
|
||||
|
||||
fun func() {
|
||||
val b = 1
|
||||
val a = object {
|
||||
val <!UNUSED_VARIABLE!>a<!> = object {
|
||||
val x = b
|
||||
{
|
||||
<!VAL_REASSIGNMENT!>b<!> = 4
|
||||
<!VAL_REASSIGNMENT!>b<!> = <!UNUSED_VALUE!>4<!>
|
||||
<!UNRESOLVED_REFERENCE!>$b<!> = 3
|
||||
}
|
||||
}
|
||||
@@ -349,4 +349,4 @@ fun test(m : M) {
|
||||
fun test1(m : M) {
|
||||
<!VAL_REASSIGNMENT!>m.x<!>++
|
||||
m.y--
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
fun foo(f : fun()) {
|
||||
val x : Unit = f()
|
||||
val <!UNUSED_VARIABLE!>x<!> : Unit = f()
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
namespace unused_variables
|
||||
|
||||
fun testSimpleCases() {
|
||||
var i = 2
|
||||
i = <!UNUSED_VALUE!>34<!>
|
||||
i = 34
|
||||
doSmth(i)
|
||||
i = <!UNUSED_VALUE!>5<!>
|
||||
|
||||
var j = 2
|
||||
j = <!UNUSED_CHANGED_VALUE!>j++<!>
|
||||
j = <!UNUSED_CHANGED_VALUE, UNUSED_VALUE!>j--<!>
|
||||
}
|
||||
|
||||
class IncDec() {
|
||||
fun inc() : IncDec = this
|
||||
fun dec() : IncDec = this
|
||||
}
|
||||
|
||||
class MyTest() {
|
||||
fun testIncDec() {
|
||||
var x = IncDec()
|
||||
x++
|
||||
++x
|
||||
x--
|
||||
--x
|
||||
x = <!UNUSED_CHANGED_VALUE!>x++<!>
|
||||
x = <!UNUSED_CHANGED_VALUE!>x--<!>
|
||||
x = ++x
|
||||
x = <!UNUSED_VALUE!>--x<!>
|
||||
}
|
||||
|
||||
var a: String = "s"
|
||||
set(v: String) {
|
||||
var i: Int = 23
|
||||
doSmth(i)
|
||||
i = <!UNUSED_VALUE!>34<!>
|
||||
$a = v
|
||||
}
|
||||
|
||||
{
|
||||
a = "rr"
|
||||
}
|
||||
|
||||
fun testSimple() {
|
||||
a = "rro"
|
||||
|
||||
var <!UNUSED_VARIABLE!>i<!> = 1;
|
||||
i = <!UNUSED_VALUE!>34<!>;
|
||||
i = <!UNUSED_VALUE!>456<!>;
|
||||
}
|
||||
|
||||
fun testWhile(a : Any?, b : Any?) {
|
||||
var a : Any? = true
|
||||
var b : Any? = 34
|
||||
while (a is Any) {
|
||||
a = null
|
||||
}
|
||||
while (b != null) {
|
||||
a = <!UNUSED_VALUE!>null<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testIf() {
|
||||
var a : Any
|
||||
if (1 < 2) {
|
||||
a = 23
|
||||
}
|
||||
else {
|
||||
a = "ss"
|
||||
doSmth(a as String)
|
||||
}
|
||||
doSmth(a)
|
||||
|
||||
if (1 < 2) {
|
||||
a = <!UNUSED_VALUE!>23<!>
|
||||
}
|
||||
else {
|
||||
a = <!UNUSED_VALUE!>"ss"<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testFor() {
|
||||
for (i in 1..10) {
|
||||
doSmth(i)
|
||||
}
|
||||
}
|
||||
|
||||
fun doSmth(s: String) {}
|
||||
fun doSmth(a: Any) {}
|
||||
}
|
||||
|
||||
fun testInnerFunctions() {
|
||||
var <!UNUSED_VARIABLE!>y<!> = 1
|
||||
fun foo() {
|
||||
y = <!UNUSED_VALUE!>1<!>
|
||||
}
|
||||
var z = 1
|
||||
fun bar() {
|
||||
doSmth(z)
|
||||
}
|
||||
}
|
||||
|
||||
fun testFunctionLiterals() {
|
||||
var x = 1
|
||||
var <!UNUSED_VARIABLE!>fl<!> = { (): Int =>
|
||||
x
|
||||
}
|
||||
var y = 2
|
||||
var <!UNUSED_VARIABLE!>fl1<!> = { (): Unit =>
|
||||
doSmth(y)
|
||||
}
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
fun testObject() : Trait {
|
||||
val x = 24
|
||||
val o = object : Trait {
|
||||
val y : Int //in this case y should not be marked as unused
|
||||
get() = 55
|
||||
|
||||
override fun foo() {
|
||||
doSmth(x)
|
||||
}
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
fun testBackingFieldsNotMarked() {
|
||||
val <!UNUSED_VARIABLE!>a<!> = object {
|
||||
val x : Int
|
||||
{
|
||||
$x = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doSmth(i : Int) {}
|
||||
@@ -4,33 +4,33 @@ namespace kt235
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val array = MyArray()
|
||||
val f = { (): String =>
|
||||
val <!UNUSED_VARIABLE!>f<!> = { (): String =>
|
||||
<!EXPECTED_TYPE_MISMATCH!>array[2] = 23<!> //error: Type mismatch: inferred type is Int (!!!) but String was expected
|
||||
}
|
||||
val g = {(): String =>
|
||||
val <!UNUSED_VARIABLE!>g<!> = {(): String =>
|
||||
var x = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x += 2<!> //no error, but it should be here
|
||||
}
|
||||
val h = {(): String =>
|
||||
val <!UNUSED_VARIABLE!>h<!> = {(): String =>
|
||||
var x = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x = 2<!> //the same
|
||||
}
|
||||
val array1 = MyArray1()
|
||||
val x = { (): String =>
|
||||
val <!UNUSED_VARIABLE!>x<!> = { (): String =>
|
||||
<!EXPECTED_TYPE_MISMATCH!>array1[2] = 23<!>
|
||||
}
|
||||
|
||||
val fi = { (): Int =>
|
||||
val <!UNUSED_VARIABLE!>fi<!> = { (): Int =>
|
||||
<!ASSIGNMENT_TYPE_MISMATCH!>array[2] = 23<!>
|
||||
}
|
||||
val gi = {(): Int =>
|
||||
val <!UNUSED_VARIABLE!>gi<!> = {(): Int =>
|
||||
var x = 1
|
||||
<!ASSIGNMENT_TYPE_MISMATCH!>x += 21<!>
|
||||
}
|
||||
|
||||
var m: MyNumber = MyNumber()
|
||||
val a = { (): MyNumber =>
|
||||
m++
|
||||
val <!UNUSED_VARIABLE!>a<!> = { (): MyNumber =>
|
||||
<!UNUSED_CHANGED_VALUE!>m++<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// KT-302 Report an error when inheriting many implementations of the same member
|
||||
|
||||
namespace kt302
|
||||
|
||||
trait A {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
trait B {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
class <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>C<!> : A, B {} //should be error here
|
||||
@@ -5,7 +5,7 @@ namespace kt352
|
||||
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //type mismatch
|
||||
|
||||
fun foo() {
|
||||
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //!!! no error
|
||||
val <!UNUSED_VARIABLE!>f<!> : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //!!! no error
|
||||
}
|
||||
|
||||
class A() {
|
||||
|
||||
@@ -5,17 +5,17 @@ trait A {
|
||||
}
|
||||
|
||||
fun foo(a: A) {
|
||||
val g : fun() : Unit = {
|
||||
val <!UNUSED_VARIABLE!>g<!> : fun() : Unit = {
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
|
||||
val u: Unit = a.gen() //type mismatch, but Unit can be derived
|
||||
val <!UNUSED_VARIABLE!>u<!>: Unit = a.gen() //type mismatch, but Unit can be derived
|
||||
|
||||
if (true) {
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
|
||||
val b : fun() : Unit = {
|
||||
val <!UNUSED_VARIABLE!>b<!> : fun() : Unit = {
|
||||
if (true) {
|
||||
a.gen() //type mismatch, but Unit can be derived
|
||||
}
|
||||
@@ -24,9 +24,9 @@ fun foo(a: A) {
|
||||
}
|
||||
}
|
||||
|
||||
val f : fun() : Int = { () : Int =>
|
||||
val <!UNUSED_VARIABLE!>f<!> : fun() : Int = { () : Int =>
|
||||
a.gen() //type mismatch, but Int can be derived
|
||||
}
|
||||
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,13 @@ fun invoker(gen : fun() : Int) : Int = 0
|
||||
|
||||
//more tests
|
||||
fun t1() {
|
||||
val v = @{ () : Int =>
|
||||
val <!UNUSED_VARIABLE!>v<!> = @{ () : Int =>
|
||||
return@ 111
|
||||
}
|
||||
}
|
||||
|
||||
fun t2() : String {
|
||||
val g : fun(): Int = @{
|
||||
val <!UNUSED_VARIABLE!>g<!> : fun(): Int = @{
|
||||
if (true) {
|
||||
return@ 1
|
||||
}
|
||||
@@ -54,10 +54,10 @@ fun t3() : String {
|
||||
}
|
||||
|
||||
fun t4() : Int {
|
||||
val h : fun (): String = @l{
|
||||
val <!UNUSED_VARIABLE!>h<!> : fun (): String = @l{
|
||||
return@l "a"
|
||||
}
|
||||
val g : fun (): String = @{ () : String =>
|
||||
val <!UNUSED_VARIABLE!>g<!> : fun (): String = @{ () : String =>
|
||||
return@ "a"
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
fun <T> funny(f : fun() : T) : T = f()
|
||||
|
||||
fun testFunny() {
|
||||
val a : Int = funny {1}
|
||||
val <!UNUSED_VARIABLE!>a<!> : Int = funny {1}
|
||||
}
|
||||
|
||||
fun <T> funny2(f : fun(t : T) : T) : T <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
|
||||
fun testFunny2() {
|
||||
val a : Int = funny2 {it}
|
||||
val <!UNUSED_VARIABLE!>a<!> : Int = funny2 {it}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
@@ -25,7 +25,7 @@ fun <T> T.with(f : fun T.()) {
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val a = 1 with {
|
||||
val <!UNUSED_VARIABLE!>a<!> = 1 with {
|
||||
plus(1)
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -10,7 +10,6 @@ class Foo {
|
||||
}
|
||||
class User {
|
||||
fun main() : Unit {
|
||||
var boo : Foo.Bar? /* <-- this reference is red */ = Foo.Bar()
|
||||
var <!UNUSED_VARIABLE!>boo<!> : Foo.Bar? /* <-- this reference is red */ = Foo.Bar()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class CheckerTestUtilTest extends JetLiteFixture {
|
||||
doTest(new TheTest("Unexpected NONE_APPLICABLE at 122 to 123", "Missing TYPE_MISMATCH at 161 to 169") {
|
||||
@Override
|
||||
protected void makeTestData(List<Diagnostic> diagnostics, List<CheckerTestUtil.DiagnosedRange> diagnosedRanges) {
|
||||
diagnosedRanges.remove(2);
|
||||
diagnosedRanges.remove(3);
|
||||
diagnostics.remove(diagnostics.size() - 3);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -61,6 +61,9 @@ public class TypeInfoTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
public void testIsWithGenerics() throws Exception {
|
||||
// TODO: http://youtrack.jetbrains.net/issue/KT-612
|
||||
if (true) return;
|
||||
|
||||
loadFile();
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<codeInsight.implementMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler"/>
|
||||
<codeInsight.overrideMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler"/>
|
||||
|
||||
<!-- <java.elementFinder implementation="org.jetbrains.jet.plugin.java.JavaElementFinder"/>-->
|
||||
<java.elementFinder implementation="org.jetbrains.jet.plugin.java.JavaElementFinder"/>
|
||||
<toolWindow id="CodeWindow"
|
||||
factoryClass="org.jetbrains.jet.plugin.internal.codewindow.BytecodeToolwindow$Factory"
|
||||
anchor="right"/>
|
||||
|
||||
@@ -88,6 +88,9 @@ public class JetPsiChecker implements Annotator {
|
||||
}
|
||||
else if (diagnostic.getSeverity() == Severity.WARNING) {
|
||||
annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
|
||||
if (diagnostic.getFactory() == Errors.UNUSED_VARIABLE) {
|
||||
annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
|
||||
}
|
||||
}
|
||||
if (annotation != null) {
|
||||
if (diagnostic instanceof DiagnosticWithPsiElementImpl && diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -13,24 +14,33 @@ import java.util.List;
|
||||
* @author svtk
|
||||
*/
|
||||
public class ImportClassHelper {
|
||||
public static void perform(@NotNull JetType type, @NotNull PsiElement element, @NotNull PsiElement newElement) {
|
||||
PsiElement parent = element;
|
||||
public static void perform(@NotNull JetType type, @NotNull PsiElement elementToReplace, @NotNull PsiElement newElement) {
|
||||
if (JetPluginUtil.checkTypeIsStandard(type, elementToReplace.getProject()) || ErrorUtils.isError(type.getMemberScope().getContainingDeclaration())) {
|
||||
elementToReplace.replace(newElement);
|
||||
return;
|
||||
}
|
||||
perform(JetPluginUtil.computeTypeFullName(type), elementToReplace, newElement);
|
||||
}
|
||||
|
||||
public static void perform(@NotNull String typeFullName, @NotNull JetNamespace namespace) {
|
||||
perform(typeFullName, namespace, null, null);
|
||||
}
|
||||
|
||||
public static void perform(@NotNull String typeFullName, @NotNull PsiElement elementToReplace, @NotNull PsiElement newElement) {
|
||||
PsiElement parent = elementToReplace;
|
||||
while (!(parent instanceof JetNamespace)) {
|
||||
parent = parent.getParent();
|
||||
assert parent != null;
|
||||
}
|
||||
JetNamespace namespace = (JetNamespace) parent;
|
||||
perform(typeFullName, (JetNamespace) parent, elementToReplace, newElement);
|
||||
}
|
||||
|
||||
public static void perform(@NotNull String typeFullName, @NotNull JetNamespace namespace, @Nullable PsiElement elementToReplace, @Nullable PsiElement newElement) {
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
if (JetPluginUtil.checkTypeIsStandard(type, element.getProject()) || ErrorUtils.isError(type.getMemberScope().getContainingDeclaration())) {
|
||||
element.replace(newElement);
|
||||
return;
|
||||
}
|
||||
|
||||
String typeFullName = JetPluginUtil.computeTypeFullName(type);
|
||||
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(element.getProject(), typeFullName);
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(namespace.getProject(), typeFullName);
|
||||
|
||||
String lineSeparator = System.getProperty("line.separator");
|
||||
if (!importDirectives.isEmpty()) {
|
||||
boolean isPresent = false;
|
||||
for (JetImportDirective directive : importDirectives) {
|
||||
@@ -42,7 +52,7 @@ public class ImportClassHelper {
|
||||
if (!isPresent) {
|
||||
JetImportDirective lastDirective = importDirectives.get(importDirectives.size() - 1);
|
||||
lastDirective.getParent().addAfter(newDirective, lastDirective);
|
||||
lastDirective.getParent().addAfter(JetPsiFactory.createWhiteSpace(element.getProject(), "\n"), lastDirective);
|
||||
lastDirective.getParent().addAfter(JetPsiFactory.createWhiteSpace(namespace.getProject(), lineSeparator), lastDirective);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -50,9 +60,10 @@ public class ImportClassHelper {
|
||||
assert !declarations.isEmpty();
|
||||
JetDeclaration firstDeclaration = declarations.iterator().next();
|
||||
firstDeclaration.getParent().addBefore(newDirective, firstDeclaration);
|
||||
firstDeclaration.getParent().addBefore(JetPsiFactory.createWhiteSpace(element.getProject(), "\n\n"), firstDeclaration);
|
||||
firstDeclaration.getParent().addBefore(JetPsiFactory.createWhiteSpace(namespace.getProject(), lineSeparator + lineSeparator), firstDeclaration);
|
||||
}
|
||||
if (elementToReplace != null && newElement != null && elementToReplace != newElement) {
|
||||
elementToReplace.replace(newElement);
|
||||
}
|
||||
element.replace(newElement);
|
||||
parent.replace(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,6 @@ abstract class B3(i: Int) {
|
||||
}
|
||||
|
||||
fun foo(a: B3) {
|
||||
val a = <error>B3()</error>
|
||||
val b = <error>B1(2, "s")</error>
|
||||
val <warning>a</warning> = <error>B3()</error>
|
||||
val <warning>b</warning> = <error>B1(2, "s")</error>
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class WithC() {
|
||||
}
|
||||
|
||||
this(a : Int) : this() {
|
||||
val b = x
|
||||
val <warning>b</warning> = x
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ fun A.plus(a : Int) {
|
||||
fun <T> T.minus(t : T) : Int = 1
|
||||
|
||||
fun test() {
|
||||
val y = 1.abs
|
||||
val <warning>y</warning> = 1.abs
|
||||
}
|
||||
val Int.abs : Int
|
||||
get() = if (this > 0) this else -this;
|
||||
|
||||
@@ -9,10 +9,10 @@ fun testIncDec() {
|
||||
++x
|
||||
x--
|
||||
--x
|
||||
x = x++
|
||||
x = x--
|
||||
x = <warning>x++</warning>
|
||||
x = <warning>x--</warning>
|
||||
x = ++x
|
||||
x = --x
|
||||
x = <warning>--x</warning>
|
||||
}
|
||||
|
||||
class WrongIncDec() {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace qualified_expressions
|
||||
|
||||
fun test(s: String?) {
|
||||
val a: Int = <error>s?.length</error>
|
||||
val <warning>a</warning>: Int = <error>s?.length</error>
|
||||
val b: Int? = s?.length
|
||||
val c: Int = s?.length ?: -11
|
||||
val d: Int = s?.length ?: <error>"empty"</error>
|
||||
val <warning>c</warning>: Int = s?.length ?: -11
|
||||
val <warning>d</warning>: Int = s?.length ?: <error>"empty"</error>
|
||||
val e: String = <error>s?.length</error> ?: "empty"
|
||||
val f: Int = s?.length ?: b ?: 1
|
||||
val g: Int? = e? startsWith("s")?.length
|
||||
val <warning>f</warning>: Int = s?.length ?: b ?: 1
|
||||
val <warning>g</warning>: Int? = e? startsWith("s")?.length
|
||||
}
|
||||
@@ -31,9 +31,9 @@ namespace closures {
|
||||
val Int.xx = this : Int
|
||||
fun Char.xx() : Any {
|
||||
this : Char
|
||||
val a = {Double.() => this : Double + this@xx : Char}
|
||||
val b = @a{Double.() => this@a : Double + this@xx : Char}
|
||||
val c = @a{() => <error>this@a</error> + this@xx : Char}
|
||||
val <warning>a</warning> = {Double.() => this : Double + this@xx : Char}
|
||||
val <warning>b</warning> = @a{Double.() => this@a : Double + this@xx : Char}
|
||||
val <warning>c</warning> = @a{() => <error>this@a</error> + this@xx : Char}
|
||||
return (@a{Double.() => this@a : Double + this@xx : Char})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import java.lang.Comparable as Com
|
||||
val l : List<in Int> = ArrayList<Int>()
|
||||
|
||||
fun test(l : java.util.List<Int>) {
|
||||
val x : java.<error>List</error>
|
||||
val y : java.util.List<Int>
|
||||
val b : java.lang.Object
|
||||
val a : util.List<Int>
|
||||
val z : java.<error>utils</error>.List<Int>
|
||||
val <warning>x</warning> : java.<error>List</error>
|
||||
val <warning>y</warning> : java.util.List<Int>
|
||||
val <warning>b</warning> : java.lang.Object
|
||||
val <warning>a</warning> : util.List<Int>
|
||||
val <warning>z</warning> : java.<error>utils</error>.List<Int>
|
||||
|
||||
val f : java.io.File? = null
|
||||
val <warning>f</warning> : java.io.File? = null
|
||||
|
||||
Collections.<error>emptyList</error>
|
||||
Collections.emptyList<Int>
|
||||
@@ -27,7 +27,7 @@ fun test(l : java.util.List<Int>) {
|
||||
<error>List</error><Int>
|
||||
|
||||
|
||||
val o = "sdf" <warning>as</warning> Object
|
||||
val <warning>o</warning> = "sdf" <warning>as</warning> Object
|
||||
|
||||
try {
|
||||
// ...
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace unresolved
|
||||
|
||||
fun testGenericArgumentsCount() {
|
||||
val p1: Tuple2<error><Int></error> = (2, 2)
|
||||
val p2: <error>Tuple2</error> = (2, 2)
|
||||
val <warning>p1</warning>: Tuple2<error><Int></error> = (2, 2)
|
||||
val <warning>p2</warning>: <error>Tuple2</error> = (2, 2)
|
||||
}
|
||||
|
||||
fun testUnresolved() {
|
||||
if (<error>a</error> is String) {
|
||||
val s = <error>a</error>
|
||||
val <warning>s</warning> = <error>a</error>
|
||||
}
|
||||
<error>foo</error>(<error>a</error>)
|
||||
val s = "s"
|
||||
|
||||
@@ -8,13 +8,13 @@ abstract class Usual<T> {}
|
||||
|
||||
fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
|
||||
val c1: Consumer<Any> = <error>c</error>
|
||||
val c2: Consumer<Int> = c1
|
||||
val <warning>c2</warning>: Consumer<Int> = c1
|
||||
|
||||
val p1: Producer<Any> = p
|
||||
val p2: Producer<Int> = <error>p1</error>
|
||||
val <warning>p2</warning>: Producer<Int> = <error>p1</error>
|
||||
|
||||
val u1: Usual<Any> = <error>u</error>
|
||||
val u2: Usual<Int> = <error>u1</error>
|
||||
val <warning>u2</warning>: Usual<Int> = <error>u1</error>
|
||||
}
|
||||
|
||||
//Arrays copy example
|
||||
|
||||
@@ -163,42 +163,42 @@ fun illegalWhenBlock(a: Any): Int {
|
||||
}
|
||||
fun declarations(a: Any?) {
|
||||
if (a is String) {
|
||||
val p4: (Int, String) = (2, <info descr="Automatically cast to String">a</info>)
|
||||
val <warning>p4</warning>: (Int, String) = (2, <info descr="Automatically cast to String">a</info>)
|
||||
}
|
||||
if (a is String?) {
|
||||
if (a != null) {
|
||||
val s: String = <info descr="Automatically cast to String">a</info>
|
||||
val <warning>s</warning>: String = <info descr="Automatically cast to String">a</info>
|
||||
}
|
||||
}
|
||||
if (a != null) {
|
||||
if (a is String?) {
|
||||
val s: String = <info descr="Automatically cast to String">a</info>
|
||||
val <warning>s</warning>: String = <info descr="Automatically cast to String">a</info>
|
||||
}
|
||||
}
|
||||
}
|
||||
fun vars(a: Any?) {
|
||||
var b: Int = 0
|
||||
var <warning>b</warning>: Int = 0
|
||||
if (a is Int) {
|
||||
b = <info descr="Automatically cast to Int">a</info>
|
||||
b = <info descr="Automatically cast to Int"><warning>a</warning></info>
|
||||
}
|
||||
}
|
||||
fun tuples(a: Any?) {
|
||||
if (a != null) {
|
||||
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
|
||||
val <warning>s</warning>: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
|
||||
}
|
||||
if (a is String) {
|
||||
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
val <warning>s</warning>: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
}
|
||||
fun illegalTupleReturnType(): (Any, String) = (<error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Any was expected">a</error>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
|
||||
if (a is String) {
|
||||
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
}
|
||||
val illegalFunctionLiteral: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
|
||||
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
|
||||
val <warning>illegalFunctionLiteral</warning>: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
|
||||
val <warning>illegalReturnValueInFunctionLiteral</warning>: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
|
||||
|
||||
if (a is Int) {
|
||||
val legalFunctionLiteral: Function0<Int> = { <info descr="Automatically cast to Int">a</info> }
|
||||
val alsoLegalFunctionLiteral: Function0<Int> = { (): Int => <info descr="Automatically cast to Int">a</info> }
|
||||
val <warning>legalFunctionLiteral</warning>: Function0<Int> = { <info descr="Automatically cast to Int">a</info> }
|
||||
val <warning>alsoLegalFunctionLiteral</warning>: Function0<Int> = { (): Int => <info descr="Automatically cast to Int">a</info> }
|
||||
}
|
||||
}
|
||||
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
|
||||
@@ -225,7 +225,7 @@ fun mergeAutocasts(a: Any?) {
|
||||
is String, is Any => a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
|
||||
}
|
||||
if (a is String && a is Any) {
|
||||
val i: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
|
||||
val <warning>i</warning>: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
|
||||
}
|
||||
if (a is String && <info descr="Automatically cast to String">a</info>.compareTo("") == 0) {}
|
||||
if (a is String || a.<error descr="Unresolved reference: compareTo">compareTo</error>("") == 0) {}
|
||||
@@ -235,9 +235,9 @@ fun mergeAutocasts(a: Any?) {
|
||||
fun f(): String {
|
||||
var a: Any = 11
|
||||
if (a is String) {
|
||||
val i: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
|
||||
val <warning>i</warning>: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
|
||||
<error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>.compareTo("f")
|
||||
val f: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error> }
|
||||
val <warning>f</warning>: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error> }
|
||||
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
fun refs() {
|
||||
var <info>a</info> = 1
|
||||
val v = {
|
||||
<info>a</info> = 2
|
||||
var <info><warning>a</warning></info> = 1
|
||||
val <warning>v</warning> = {
|
||||
<info>a</info> = <warning>2</warning>
|
||||
}
|
||||
|
||||
var <info>x</info> = 1
|
||||
val b = object {
|
||||
var <info><warning>x</warning></info> = 1
|
||||
val <warning>b</warning> = object {
|
||||
fun foo() {
|
||||
<info>x</info> = 2
|
||||
<info>x</info> = <warning>2</warning>
|
||||
}
|
||||
}
|
||||
|
||||
var <info>y</info> = 1
|
||||
var <info><warning>y</warning></info> = 1
|
||||
fun foo() {
|
||||
<info>y</info> = 1
|
||||
<info>y</info> = <warning>1</warning>
|
||||
}
|
||||
}
|
||||
|
||||
fun refsPlusAssign() {
|
||||
var <info>a</info> = 1
|
||||
val v = {
|
||||
val <warning>v</warning> = {
|
||||
<info>a</info> += 2
|
||||
}
|
||||
|
||||
var <info>x</info> = 1
|
||||
val b = object {
|
||||
val <warning>b</warning> = object {
|
||||
fun foo() {
|
||||
<info>x</info> += 2
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ fun test() {
|
||||
var a : Any? = null
|
||||
if (a is Any) else a = null;
|
||||
while (a is Any) a = null
|
||||
while (true) a = null
|
||||
while (true) a = <warning>null</warning>
|
||||
}
|
||||
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
|
||||
|
||||
fun test() : Int {
|
||||
foo(<error>1</error>)
|
||||
val a : fun() : Unit = {
|
||||
val <warning>a</warning> : fun() : Unit = {
|
||||
foo(<error>1</error>)
|
||||
}
|
||||
return 1
|
||||
|
||||
@@ -32,7 +32,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||
fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||
val lhs = evaluateAdd(expr, numbers)
|
||||
if (expr.length() > 0) {
|
||||
val c = expr.charAt(0)
|
||||
val <warning>c</warning> = expr.charAt(0)
|
||||
expr.deleteCharAt(0)
|
||||
}
|
||||
return lhs
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
fun foo1() : fun (Int) : Int = { (x: Int) => x }
|
||||
|
||||
fun foo() {
|
||||
val h : fun (Int) : Int = foo1();
|
||||
val <warning>h</warning> : fun (Int) : Int = foo1();
|
||||
h(1)
|
||||
val m : fun (Int) : Int = {(a : Int) => 1}//foo1()
|
||||
val <warning>m</warning> : fun (Int) : Int = {(a : Int) => 1}//foo1()
|
||||
m(1)
|
||||
}
|
||||
@@ -18,5 +18,5 @@ enum class Foo<T> {
|
||||
|
||||
|
||||
fun box() {
|
||||
val x: ProtocolState = ProtocolState.WAITING
|
||||
val <warning>x</warning>: ProtocolState = ProtocolState.WAITING
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
bar = 1
|
||||
this.bar
|
||||
1 : Int
|
||||
val a : Int =1
|
||||
val <warning>a</warning> : Int =1
|
||||
this : Foo
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user