Merge remote branch 'origin/master'

This commit is contained in:
Andrey Breslav
2011-11-24 22:43:16 +03:00
101 changed files with 659 additions and 509 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -30,7 +31,7 @@ public class GenerationState {
public GenerationState(Project project, ClassBuilderFactory builderFactory) {
this.project = project;
this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project, true);
this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project);
this.factory = new ClassFileFactory(builderFactory, this);
this.intrinsics = new IntrinsicMethods(project, standardLibrary);
}
@@ -82,7 +83,7 @@ public class GenerationState {
public void compile(JetFile psiFile) {
final JetNamespace namespace = psiFile.getRootNamespace();
final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY);
final BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY);
AnalyzingUtils.throwExceptionOnErrors(bindingContext);
compileCorrectNamespaces(bindingContext, Collections.singletonList(namespace));
// NamespaceCodegen codegen = forNamespace(namespace);
@@ -113,6 +114,7 @@ public class GenerationState {
}
catch (Throwable e) {
errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl());
DiagnosticUtils.throwIfRunningOnServer(e);
}
}
}
@@ -84,7 +84,7 @@ public class CompileSession {
}
return false;
}
final AnalyzingUtils instance = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true);
final AnalyzingUtils instance = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS);
List<JetNamespace> allNamespaces = new ArrayList<JetNamespace>(mySourceFileNamespaces);
allNamespaces.addAll(myLibrarySourceFileNamespaces);
myBindingContext = instance.analyzeNamespaces(myEnvironment.getProject(), allNamespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
@@ -11,6 +11,7 @@ import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -34,7 +35,7 @@ public class AnalyzerFacade {
}
};
private static final AnalyzingUtils ANALYZING_UTILS = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true);
private static final AnalyzingUtils ANALYZING_UTILS = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS);
private final static Key<CachedValue<BindingContext>> BINDING_CONTEXT = Key.create("BINDING_CONTEXT");
private static final Object lock = new Object();
@@ -68,18 +69,8 @@ public class AnalyzerFacade {
throw e;
}
catch (Throwable e) {
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor.
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true")) {
if (e instanceof RuntimeException) {
RuntimeException runtimeException = (RuntimeException) e;
throw runtimeException;
}
if (e instanceof Error) {
Error error = (Error) e;
throw error;
}
throw new RuntimeException(e);
}
DiagnosticUtils.throwIfRunningOnServer(e);
e.printStackTrace();
BindingTraceContext bindingTraceContext = new BindingTraceContext();
bindingTraceContext.report(Errors.EXCEPTION_WHILE_ANALYZING.on(file, e));
@@ -93,5 +84,4 @@ public class AnalyzerFacade {
}
return bindingContextCachedValue.getValue();
}
}
@@ -17,11 +17,7 @@ public class JetSemanticServices {
}
public static JetSemanticServices createSemanticServices(Project project) {
return createSemanticServices(project, true);
}
public static JetSemanticServices createSemanticServices(Project project, boolean loadFullLibrary) {
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project, loadFullLibrary));
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project));
}
private final JetStandardLibrary standardLibrary;
@@ -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() {
@@ -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;
}
@@ -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);
@@ -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();
}
}
@@ -81,4 +81,19 @@ public class DiagnosticUtils {
}
return position;
}
public static void throwIfRunningOnServer(Throwable e) {
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor.
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true")) {
if (e instanceof RuntimeException) {
RuntimeException runtimeException = (RuntimeException) e;
throw runtimeException;
}
if (e instanceof Error) {
Error error = (Error) e;
throw error;
}
throw new RuntimeException(e);
}
}
}
@@ -16,7 +16,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING;
@@ -146,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
@@ -276,10 +288,7 @@ public interface Errors {
ParameterizedDiagnosticFactory2<JetType, Integer> TYPE_MISMATCH_IN_TUPLE_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message
ParameterizedDiagnosticFactory2<JetType, JetType> TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}");
ParameterizedDiagnosticFactory2<JetType, JetType> INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}");
ParameterizedDiagnosticFactory1<JetType> CANNOT_CHECK_FOR_ERASED = ParameterizedDiagnosticFactory1.create(ERROR, "Cannot check for instance of erased type: {0}");
ParameterizedDiagnosticFactory2<JetType, JetType> UNCHECKED_CAST = ParameterizedDiagnosticFactory2.create(WARNING, "Unchecked cast: {0} to {1}");
ParameterizedDiagnosticFactory3<TypeParameterDescriptor, ClassDescriptor, Collection<JetType>> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3<TypeParameterDescriptor, ClassDescriptor, Collection<JetType>>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") {
@Override
protected String makeMessageForA(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
@@ -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;
}
}
@@ -28,8 +28,8 @@ import java.util.*;
* @author abreslav
*/
public class AnalyzingUtils {
public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy, boolean loadStdlib) {
return new AnalyzingUtils(importingStrategy, loadStdlib);
public static AnalyzingUtils getInstance(@NotNull ImportingStrategy importingStrategy) {
return new AnalyzingUtils(importingStrategy);
}
public static void checkForSyntacticErrors(@NotNull PsiElement root) {
@@ -53,11 +53,9 @@ public class AnalyzingUtils {
}
private final ImportingStrategy importingStrategy;
private final boolean loadStdlib;
private AnalyzingUtils(ImportingStrategy importingStrategy, boolean loadStdlib) {
private AnalyzingUtils(ImportingStrategy importingStrategy) {
this.importingStrategy = importingStrategy;
this.loadStdlib = loadStdlib;
}
public BindingContext analyzeNamespace(@NotNull JetNamespace namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
@@ -73,7 +71,7 @@ public class AnalyzingUtils {
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project, loadStdlib);
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
ModuleDescriptor owner = new ModuleDescriptor("<module>");
@@ -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;
}
@@ -29,24 +29,16 @@ import java.util.Set;
public class JetStandardLibrary {
// TODO : consider releasing this memory
private static JetStandardLibrary cachedFullLibrary = null;
private static JetStandardLibrary cachedQuickLibrary = null;
private static JetStandardLibrary cachedLibrary = null;
// private static final Map<Project, JetStandardLibrary> standardLibraryCache = new HashMap<Project, JetStandardLibrary>();
// TODO : double checked locking
synchronized
public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project, boolean loadFullLibrary) {
if (loadFullLibrary) {
if (cachedFullLibrary == null) {
cachedFullLibrary = new JetStandardLibrary(project, true);
}
return cachedFullLibrary;
} else {
if (cachedQuickLibrary == null) {
cachedQuickLibrary = new JetStandardLibrary(project, false);
}
return cachedQuickLibrary;
public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) {
if (cachedLibrary == null) {
cachedLibrary = new JetStandardLibrary(project);
}
return cachedLibrary;
// JetStandardLibrary standardLibrary = standardLibraryCache.get(project);
// if (standardLibrary == null) {
// standardLibrary = new JetStandardLibrary(project);
@@ -55,12 +47,6 @@ public class JetStandardLibrary {
// return standardLibrary;
}
public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) {
return getJetStandardLibrary(project, true);
}
private final boolean loadFullLibrary;
private JetScope libraryScope;
private ClassDescriptor numberClass;
@@ -136,27 +122,20 @@ public class JetStandardLibrary {
private NamespaceDescriptor typeInfoNamespace;
private Set<FunctionDescriptor> typeInfoFunction;
private JetStandardLibrary(@NotNull Project project, boolean loadFullLibrary) {
this.loadFullLibrary = loadFullLibrary;
private JetStandardLibrary(@NotNull Project project) {
// TODO : review
InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet");
try {
JetFile file = null;
if (loadFullLibrary) {
// TODO : review
InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet");
//noinspection IOResourceOpenedButNotSafelyClosed
file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet",
JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
}
//noinspection IOResourceOpenedButNotSafelyClosed
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet",
JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
BindingTraceContext bindingTraceContext = new BindingTraceContext();
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
if (loadFullLibrary) {
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
}
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
// this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());
@@ -174,11 +153,6 @@ public class JetStandardLibrary {
private void initStdClasses() {
if(libraryScope == null) {
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
if (!loadFullLibrary) {
return;
}
this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number");
this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte");
this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char");
@@ -1,7 +1,6 @@
package org.jetbrains.jet.lang.types.expressions;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType;
@@ -9,7 +8,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
@@ -247,58 +245,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
else {
if (typeChecker.isSubtypeOf(actualType, targetType)) {
context.trace.report(USELESS_CAST.on(expression, expression.getOperationSign()));
} else {
if (isCastErased(actualType, targetType)) {
context.trace.report(Errors.UNCHECKED_CAST.on(expression, actualType, targetType));
}
}
}
}
/**
* Check if assignment from ActualType to TargetType is erased.
* It is an error in "is" statement and warning in "as".
*/
public static boolean isCastErased(JetType actualType, JetType targetType) {
JetType targetTypeClerared = TypeUtils.makeUnsubstitutedType(
(ClassDescriptor) targetType.getConstructor().getDeclarationDescriptor(), null);
Multimap<TypeConstructor, TypeProjection> clearTypeSubstitutionMap =
TypeUtils.buildDeepSubstitutionMultimap(targetTypeClerared);
Set<JetType> clearSubstituted = new HashSet<JetType>();
for (int i = 0; i < actualType.getConstructor().getParameters().size(); ++i) {
TypeParameterDescriptor subjectTypeParameterDescriptor = actualType.getConstructor().getParameters().get(i);
Collection<TypeProjection> subst = clearTypeSubstitutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor());
for (TypeProjection proj : subst) {
clearSubstituted.add(proj.getType());
}
}
for (int i = 0; i < targetType.getConstructor().getParameters().size(); ++i) {
TypeParameterDescriptor typeParameter = targetType.getConstructor().getParameters().get(i);
TypeProjection typeProjection = targetType.getArguments().get(i);
if (typeParameter.isReified()) {
continue;
}
// "is List<*>"
if (typeProjection.equals(TypeUtils.makeStarProjection(typeParameter))) {
continue;
}
// if parameter is mapped to nothing then it is erased
if (!clearSubstituted.contains(typeParameter.getDefaultType())) {
return true;
}
}
return false;
}
@Override
public JetType visitTupleExpression(JetTupleExpression expression, ExpressionTypingContext context) {
List<JetExpression> entries = expression.getEntries();
@@ -1,14 +1,11 @@
package org.jetbrains.jet.lang.types.expressions;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.Ref;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
@@ -20,7 +17,8 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.jet.lang.types.*;
import java.util.*;
import java.util.List;
import java.util.Set;
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.ensureBooleanResultWithCustomSubject;
@@ -247,9 +245,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
}
}
/*
* (a: SubjectType) is Type
*/
private void checkTypeCompatibility(@Nullable JetType type, @NotNull JetType subjectType, @NotNull JetElement reportErrorOn) {
// TODO : Take auto casts into account?
if (type == null) {
@@ -258,29 +253,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
if (TypeUtils.intersect(context.semanticServices.getTypeChecker(), Sets.newHashSet(type, subjectType)) == null) {
// context.trace.getErrorHandler().genericError(reportErrorOn.getNode(), "Incompatible types: " + type + " and " + subjectType);
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType));
return;
}
{
// check parameters compatible
Multimap<TypeConstructor, TypeProjection> typeSubstritutionMap = TypeUtils.buildDeepSubstitutionMultimap(type);
for (int i = 0; i < subjectType.getConstructor().getParameters().size(); ++i) {
TypeParameterDescriptor subjectTypeParameterDescriptor = subjectType.getConstructor().getParameters().get(i);
TypeProjection subjectParameterType = subjectType.getArguments().get(i);
Collection<TypeProjection> xxy = typeSubstritutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor());
for (TypeProjection proj : xxy) {
if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectParameterType.getType(), proj.getType())) {
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType));
continue;
}
}
}
}
if (BasicExpressionTypingVisitor.isCastErased(subjectType, type)) {
context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(reportErrorOn, type));
}
}
@@ -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
}
}
@@ -1,5 +1,3 @@
// -JDK
fun test() : Unit {
var x : Int? = 0
var y : Int = 0
@@ -15,4 +13,4 @@ fun test() : Unit {
x <!USELESS_CAST!>as?<!> Int? : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as?<!> Int? : Int?
()
}
}
@@ -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
}
}
@@ -1,4 +0,0 @@
import java.util.List;
import java.util.Collection;
fun ff(c: Collection<String>) = c <!CAST_NEVER_SUCCEEDS!>as<!> List<Int>
@@ -1,4 +0,0 @@
import java.util.List;
import java.util.Collection;
fun ff(c: Collection<String>) = c as List<String>
@@ -1,4 +0,0 @@
import java.util.List;
fun ff(l: Any) = l as List<*>
@@ -1,3 +0,0 @@
import java.util.List;
fun ff(a: Any) = <!UNCHECKED_CAST!>a as List<String><!>
@@ -1,5 +0,0 @@
import java.util.Collection;
import java.util.List;
fun ff(l: Collection<String>) = l is List<String>
@@ -1,9 +0,0 @@
import java.util.Collection;
import java.util.List;
open class A
class B : A
fun ff(l: Collection<B>) = l is List<out A>
@@ -1,3 +0,0 @@
import java.util.List;
fun ff(l: Any) = l is <!CANNOT_CHECK_FOR_ERASED!>List<String><!>
@@ -1,5 +0,0 @@
import java.util.List;
import java.util.Collection;
fun ff(l: Collection<Int>) = l is <!INCOMPATIBLE_TYPES!>List<String><!>
@@ -1,3 +0,0 @@
import java.util.List;
fun ff(l: Any) = l is List<*>
@@ -1,3 +0,0 @@
class MyList<T>
fun ff(a: Any) = a is MyList<String>
@@ -1,3 +0,0 @@
class MyList<A>
fun ff(l: MyList<String>) = l is <!INCOMPATIBLE_TYPES!>MyList<Int><!>
@@ -1,4 +0,0 @@
trait Aaa
trait Bbb
fun f(a: Aaa) = a is Bbb
@@ -1,6 +0,0 @@
import java.util.List;
fun ff(l: Any) = when(l) {
is <!CANNOT_CHECK_FOR_ERASED!>List<String><!> => 1
else 2
}
@@ -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 ""
@@ -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
}
@@ -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()
}
@@ -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)
}
}
@@ -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()
}
}
}
@@ -1,6 +1,6 @@
fun typeName(a: Any?) : String {
return when(a) {
is java.util.ArrayList<*> => "array list"
is java.util.ArrayList<Int> => "array list"
else => "no idea"
}
}
@@ -8,4 +8,4 @@ fun typeName(a: Any?) : String {
fun box() : String {
if(typeName(java.util.ArrayList<Int> ()) != "array list") return "array list failed"
return "OK"
}
}
@@ -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);
}
});
@@ -81,7 +81,7 @@ public class CheckerTestUtilTest extends JetLiteFixture {
}
public void test(PsiFile psiFile) {
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE, true), (JetFile) psiFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), (JetFile) psiFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, bindingContext).toString();
List<CheckerTestUtil.DiagnosedRange> diagnosedRanges = Lists.newArrayList();
@@ -46,12 +46,10 @@ public class FullJetPsiCheckerTest extends JetLiteFixture {
myFile = createPsiFile(myName, clearText);
boolean loadStdlib = !expectedText.contains("-STDLIB");
boolean importJdk = !expectedText.contains("-JDK");
ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE;
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy, loadStdlib), myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy), myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
@Override
@@ -41,12 +41,11 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture {
createAndCheckPsiFile(name, clearText);
JetFile jetFile = (JetFile) myFile;
boolean loadStdlib = !expectedText.contains("-STDLIB");
boolean importJdk = expectedText.contains("+JDK");
ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE;
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy, loadStdlib), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
@Override
@@ -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();
@@ -44,7 +44,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
@Override
protected ExpectedResolveData getExpectedResolveData() {
Project project = getProject();
JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project, true);
JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project);
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType()));
FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType());
+1 -1
View File
@@ -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) {
@@ -80,7 +80,7 @@ public class JetCompiler implements TranslatingCompiler {
}
}
BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).analyzeNamespaces(
BindingContext bindingContext = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).analyzeNamespaces(
compileContext.getProject(), namespaces,
Predicates.<PsiFile>alwaysTrue(),
JetControlFlowDataTraceFactory.EMPTY);
@@ -6,12 +6,15 @@ package org.jetbrains.jet.plugin.internal.codewindow;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
@@ -27,6 +30,12 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import javax.swing.*;
import java.awt.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class BytecodeToolwindow extends JPanel {
private static final int UPDATE_DELAY = 500;
@@ -34,7 +43,7 @@ public class BytecodeToolwindow extends JPanel {
private final Alarm myUpdateAlarm;
private Location myCurrentLocation;
private final Project myProject;
public BytecodeToolwindow(Project project) {
super(new BorderLayout());
@@ -45,17 +54,17 @@ public class BytecodeToolwindow extends JPanel {
myUpdateAlarm.addRequest(new Runnable() {
@Override
public void run() {
myUpdateAlarm.addRequest(this, UPDATE_DELAY);
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor());
if (!Comparing.equal(location, myCurrentLocation)) {
updateBytecode(location, myCurrentLocation);
myCurrentLocation = location;
updateBytecode(location);
}
myUpdateAlarm.addRequest(this, UPDATE_DELAY);
}
}, UPDATE_DELAY);
}
private void updateBytecode(Location location) {
private void updateBytecode(Location location, Location oldLocation) {
Editor editor = location.editor;
if (editor == null) {
@@ -74,10 +83,89 @@ public class BytecodeToolwindow extends JPanel {
return;
}
setText(generateToText((JetFile) psiFile));
if (oldLocation == null || !Comparing.equal(oldLocation.editor, location.editor) || oldLocation.modificationStamp != location.modificationStamp) {
setText(generateToText((JetFile) psiFile));
}
Document document = editor.getDocument();
int startLine = document.getLineNumber(location.startOffset);
int endLine = document.getLineNumber(location.endOffset);
if (endLine > startLine && location.endOffset > 0 && document.getCharsSequence().charAt(location.endOffset - 1) == '\n') endLine--;
Document byteCodeDocument = myEditor.getDocument();
Pair<Integer, Integer> linesRange = mapLines(byteCodeDocument.getText(), startLine, endLine);
int startOffset = byteCodeDocument.getLineStartOffset(linesRange.first);
int endOffset = Math.min(byteCodeDocument.getLineStartOffset(linesRange.second + 1), byteCodeDocument.getTextLength());
myEditor.getCaretModel().moveToOffset(endOffset);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
myEditor.getCaretModel().moveToOffset(startOffset);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
myEditor.getSelectionModel().setSelection(startOffset,
endOffset);
}
}
private static Pair<Integer, Integer> mapLines(String text, int startLine, int endLine) {
int byteCodeLine = 0;
int byteCodeStartLine = -1;
int byteCodeEndLine = -1;
List<Integer> lines = new ArrayList<Integer>();
for (String line : text.split("\n")) {
line = line.trim();
if (line.startsWith("LINENUMBER")) {
int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1;
lines.add(ktLineNum);
}
}
Collections.sort(lines);
for (Integer line : lines) {
if (line >= startLine) {
startLine = line;
break;
}
}
for (String line : text.split("\n")) {
line = line.trim();
if (line.startsWith("LINENUMBER")) {
int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1;
if (byteCodeStartLine < 0 && ktLineNum == startLine) {
byteCodeStartLine = byteCodeLine;
}
if (byteCodeStartLine > 0&& ktLineNum > endLine) {
byteCodeEndLine = byteCodeLine - 1;
break;
}
}
if (byteCodeStartLine >= 0 && (line.startsWith("MAXSTACK") || line.startsWith("LOCALVARIABLE") || line.isEmpty())) {
byteCodeEndLine = byteCodeLine - 1;
break;
}
byteCodeLine++;
}
if (byteCodeStartLine == -1 || byteCodeEndLine == -1) {
return new Pair<Integer, Integer>(0, 0);
}
else {
return new Pair<Integer, Integer>(byteCodeStartLine, byteCodeEndLine);
}
}
private void setText(final String text) {
new WriteCommandAction(myProject) {
@Override
@@ -93,7 +181,9 @@ public class BytecodeToolwindow extends JPanel {
AnalyzingUtils.checkForSyntacticErrors(file);
state.compile(file);
} catch (Exception e) {
return e.toString();
StringWriter out = new StringWriter(1024);
e.printStackTrace(new PrintWriter(out));
return out.toString();
}
@@ -211,7 +211,7 @@ public class JavaElementFinder extends PsiElementFinder {
if (dirty.size() > 0) {
final BindingContext context = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS, true).shallowAnalyzeFiles(dirty);
final BindingContext context = AnalyzingUtils.getInstance(JavaDefaultImports.JAVA_DEFAULT_IMPORTS).shallowAnalyzeFiles(dirty);
state.compileCorrectNamespaces(context, AnalyzingUtils.collectRootNamespaces(dirty));
state.getFactory().files();
}
@@ -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);
}
}
+2 -2
View File
@@ -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
}
}
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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
}
+3 -3
View File
@@ -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})
}
}
+7 -7
View File
@@ -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 {
// ...
+3 -3
View File
@@ -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"
+3 -3
View File
@@ -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
+14 -14
View File
@@ -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 ""
+10 -10
View File
@@ -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
+2 -2
View File
@@ -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)
}
+1 -1
View File
@@ -18,5 +18,5 @@ enum class Foo<T> {
fun box() {
val x: ProtocolState = ProtocolState.WAITING
val <warning>x</warning>: ProtocolState = ProtocolState.WAITING
}

Some files were not shown because too many files have changed in this diff Show More