Merge branch 'master' of git+ssh://git.labs.intellij.net/jet
This commit is contained in:
@@ -4,15 +4,13 @@ import com.intellij.psi.util.PsiTreeUtil;
|
|||||||
import gnu.trove.THashSet;
|
import gnu.trove.THashSet;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
import org.jetbrains.jet.lang.resolve.calls.ExpressionAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -115,10 +113,22 @@ public class CodegenUtil {
|
|||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
String parentFQName = getFQName(parent);
|
String parentFQName = getFQName(parent);
|
||||||
if (parentFQName.length() > 0) {
|
if (parentFQName.length() > 0) {
|
||||||
return parentFQName + "." + jetNamespace.getName();
|
return parentFQName + "." + getFQName(jetNamespace.getHeader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jetNamespace.getName(); // TODO: Must include module root namespace
|
return getFQName(jetNamespace.getHeader()); // TODO: Must include module root namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFQName(JetNamespaceHeader header) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (Iterator<JetSimpleNameExpression> iterator = header.getParentNamespaceNames().iterator(); iterator.hasNext(); ) {
|
||||||
|
JetSimpleNameExpression nameExpression = iterator.next();
|
||||||
|
builder.append(nameExpression.getReferencedName());
|
||||||
|
builder.append(".");
|
||||||
|
}
|
||||||
|
// PsiElement nameIdentifier = header.getNameIdentifier();
|
||||||
|
builder.append(header.getName());
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFQName(JetClass jetClass) {
|
public static String getFQName(JetClass jetClass) {
|
||||||
|
|||||||
@@ -142,5 +142,5 @@ public interface JetNodeTypes {
|
|||||||
JetNodeType WHEN_CONDITION_IN_RANGE = new JetNodeType("WHEN_CONDITION_IN_RANGE", JetWhenConditionInRange.class);
|
JetNodeType WHEN_CONDITION_IN_RANGE = new JetNodeType("WHEN_CONDITION_IN_RANGE", JetWhenConditionInRange.class);
|
||||||
JetNodeType WHEN_CONDITION_IS_PATTERN = new JetNodeType("WHEN_CONDITION_IS_PATTERN", JetWhenConditionIsPattern.class);
|
JetNodeType WHEN_CONDITION_IS_PATTERN = new JetNodeType("WHEN_CONDITION_IS_PATTERN", JetWhenConditionIsPattern.class);
|
||||||
|
|
||||||
JetNodeType NAMESPACE_NAME = new JetNodeType("NAMESPACE_NAME", JetContainerNode.class);
|
JetNodeType NAMESPACE_HEADER = new JetNodeType("NAMESPACE_HEADER", JetNamespaceHeader.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,26 +35,30 @@ public class JetControlFlowProcessor {
|
|||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generate(@NotNull JetDeclaration subroutineElement, @NotNull JetExpression body) {
|
public void generate(@NotNull JetDeclaration subroutine) {
|
||||||
generateSubroutineControlFlow(subroutineElement, Collections.singletonList(body));
|
builder.enterSubroutine(subroutine);
|
||||||
}
|
if (subroutine instanceof JetDeclarationWithBody) {
|
||||||
|
JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine;
|
||||||
public void generateSubroutineControlFlow(@NotNull JetDeclaration subroutineElement, @NotNull List<? extends JetElement> body) {
|
CFPVisitor cfpVisitor = new CFPVisitor(false);
|
||||||
builder.enterSubroutine(subroutineElement);
|
List<JetParameter> valueParameters = declarationWithBody.getValueParameters();
|
||||||
for (JetElement statement : body) {
|
for (JetParameter valueParameter : valueParameters) {
|
||||||
statement.accept(new CFPVisitor(false));
|
valueParameter.accept(cfpVisitor);
|
||||||
|
}
|
||||||
|
JetExpression bodyExpression = declarationWithBody.getBodyExpression();
|
||||||
|
if (bodyExpression != null) {
|
||||||
|
bodyExpression.accept(cfpVisitor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
builder.exitSubroutine(subroutineElement);
|
else {
|
||||||
|
subroutine.accept(new CFPVisitor(false));
|
||||||
|
}
|
||||||
|
builder.exitSubroutine(subroutine);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processLocalDeclaration(@NotNull JetDeclaration subroutineElement, @NotNull JetExpression body) {
|
private void processLocalDeclaration(@NotNull JetDeclaration subroutine) {
|
||||||
processLocalDeclaration(subroutineElement, Collections.singletonList(body));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processLocalDeclaration(@NotNull JetDeclaration subroutineElement, @NotNull List<? extends JetElement> body) {
|
|
||||||
Label afterDeclaration = builder.createUnboundLabel();
|
Label afterDeclaration = builder.createUnboundLabel();
|
||||||
builder.nondeterministicJump(afterDeclaration);
|
builder.nondeterministicJump(afterDeclaration);
|
||||||
generateSubroutineControlFlow(subroutineElement, body);
|
generate(subroutine);
|
||||||
builder.bindLabel(afterDeclaration);
|
builder.bindLabel(afterDeclaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,6 +573,12 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitParameter(JetParameter parameter) {
|
||||||
|
builder.declare(parameter);
|
||||||
|
builder.write(parameter, parameter);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitBlockExpression(JetBlockExpression expression) {
|
public void visitBlockExpression(JetBlockExpression expression) {
|
||||||
List<JetElement> statements = expression.getStatements();
|
List<JetElement> statements = expression.getStatements();
|
||||||
@@ -582,20 +592,13 @@ public class JetControlFlowProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
public void visitNamedFunction(JetNamedFunction function) {
|
||||||
JetExpression bodyExpression = function.getBodyExpression();
|
processLocalDeclaration(function);
|
||||||
if (bodyExpression != null) {
|
|
||||||
processLocalDeclaration(function, bodyExpression);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
||||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||||
JetBlockExpression bodyExpression = functionLiteral.getBodyExpression();
|
processLocalDeclaration(functionLiteral);
|
||||||
if (bodyExpression != null) {
|
|
||||||
List<JetElement> statements = bodyExpression.getStatements();
|
|
||||||
processLocalDeclaration(functionLiteral, statements);
|
|
||||||
}
|
|
||||||
builder.read(expression);
|
builder.read(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
|||||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ public class JetFlowInformationProvider {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
JetControlFlowInstructionsGenerator instructionsGenerator = new JetControlFlowInstructionsGenerator(wrappedTrace);
|
JetControlFlowInstructionsGenerator instructionsGenerator = new JetControlFlowInstructionsGenerator(wrappedTrace);
|
||||||
new JetControlFlowProcessor(trace, instructionsGenerator).generate(declaration, bodyExpression);
|
new JetControlFlowProcessor(trace, instructionsGenerator).generate(declaration);
|
||||||
wrappedTrace.close();
|
wrappedTrace.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,13 +480,27 @@ public class JetFlowInformationProvider {
|
|||||||
}
|
}
|
||||||
else if (instruction instanceof VariableDeclarationInstruction) {
|
else if (instruction instanceof VariableDeclarationInstruction) {
|
||||||
JetDeclaration element = ((VariableDeclarationInstruction) instruction).getVariableDeclarationElement();
|
JetDeclaration element = ((VariableDeclarationInstruction) instruction).getVariableDeclarationElement();
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetNamedDeclaration) {
|
||||||
PsiElement nameIdentifier = ((JetNamedDeclaration) element).getNameIdentifier();
|
PsiElement nameIdentifier = ((JetNamedDeclaration) element).getNameIdentifier();
|
||||||
PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : element;
|
PsiElement elementToMark = nameIdentifier != null ? nameIdentifier : element;
|
||||||
if (enterData.get(variableDescriptor) == VariableStatus.UNUSED) {
|
if (enterData.get(variableDescriptor) == VariableStatus.UNUSED) {
|
||||||
trace.report(Errors.UNUSED_VARIABLE.on((JetNamedDeclaration) element, elementToMark, variableDescriptor));
|
if (element instanceof JetProperty) {
|
||||||
|
trace.report(Errors.UNUSED_VARIABLE.on((JetProperty) element, elementToMark, variableDescriptor));
|
||||||
|
}
|
||||||
|
else if (element instanceof JetParameter) {
|
||||||
|
PsiElement psiElement = element.getParent().getParent();
|
||||||
|
if (psiElement instanceof JetFunction) {
|
||||||
|
boolean isMain = (psiElement instanceof JetNamedFunction) && JetMainDetector.isMain((JetNamedFunction) psiElement);
|
||||||
|
DeclarationDescriptor descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, psiElement);
|
||||||
|
assert descriptor instanceof FunctionDescriptor;
|
||||||
|
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||||
|
if (!isMain && !functionDescriptor.getModality().isOverridable() && functionDescriptor.getOverriddenDescriptors().isEmpty()) {
|
||||||
|
trace.report(Errors.UNUSED_PARAMETER.on((JetParameter) element, elementToMark, variableDescriptor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (enterData.get(variableDescriptor) == VariableStatus.WRITTEN) {
|
else if (enterData.get(variableDescriptor) == VariableStatus.WRITTEN && element instanceof JetProperty) {
|
||||||
trace.report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on((JetNamedDeclaration) element, elementToMark, variableDescriptor));
|
trace.report(Errors.ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE.on((JetNamedDeclaration) element, elementToMark, variableDescriptor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -46,6 +46,12 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + "]";
|
try {
|
||||||
|
return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + "]";
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// DescriptionRenderer may throw if this is not yet completely initialized
|
||||||
|
// It is very inconvenient while debugging
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -83,10 +83,10 @@ public class FunctionDescriptorUtil {
|
|||||||
return parameterScope;
|
return parameterScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeFromFunctionType(@NotNull FunctionDescriptorImpl functionDescriptor, @NotNull JetType functionType) {
|
public static void initializeFromFunctionType(@NotNull FunctionDescriptorImpl functionDescriptor, @NotNull JetType functionType, @NotNull ReceiverDescriptor expectedThisObject) {
|
||||||
assert JetStandardClasses.isFunctionType(functionType);
|
assert JetStandardClasses.isFunctionType(functionType);
|
||||||
functionDescriptor.initialize(JetStandardClasses.getReceiverType(functionType),
|
functionDescriptor.initialize(JetStandardClasses.getReceiverType(functionType),
|
||||||
ReceiverDescriptor.NO_RECEIVER,
|
expectedThisObject,
|
||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
||||||
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
||||||
|
|||||||
@@ -118,6 +118,16 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
return getOutType();
|
return getOutType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetType getInType() {
|
||||||
|
return super.getInType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public JetType getOutType() {
|
||||||
|
return super.getOutType();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVar() {
|
public boolean isVar() {
|
||||||
return isVar;
|
return isVar;
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
|||||||
JetType outType = variableDescriptor.getOutType();
|
JetType outType = variableDescriptor.getOutType();
|
||||||
assert outType != null;
|
assert outType != null;
|
||||||
VariableAsFunctionDescriptor result = new VariableAsFunctionDescriptor(variableDescriptor);
|
VariableAsFunctionDescriptor result = new VariableAsFunctionDescriptor(variableDescriptor);
|
||||||
FunctionDescriptorUtil.initializeFromFunctionType(result, outType);
|
FunctionDescriptorUtil.initializeFromFunctionType(result, outType, variableDescriptor.getExpectedThisObject());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,8 +147,9 @@ public interface Errors {
|
|||||||
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT);
|
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT);
|
||||||
|
|
||||||
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
|
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
|
||||||
PsiElementOnlyDiagnosticFactory1<JetNamedDeclaration, DeclarationDescriptor> UNUSED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(WARNING, "Variable ''{0}'' is never used", NAME);
|
UnusedElementDiagnosticFactory<JetProperty, VariableDescriptor> UNUSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is never used", NAME);
|
||||||
PsiElementOnlyDiagnosticFactory1<JetNamedDeclaration, DeclarationDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(WARNING, "Variable ''{0}'' is assigned but never accessed", NAME);
|
UnusedElementDiagnosticFactory<JetParameter, VariableDescriptor> UNUSED_PARAMETER = UnusedElementDiagnosticFactory.create(WARNING, "Parameter ''{0}'' is never used", NAME);
|
||||||
|
UnusedElementDiagnosticFactory<JetNamedDeclaration, DeclarationDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, "Variable ''{0}'' is assigned but never accessed", NAME);
|
||||||
PsiElementOnlyDiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = new PsiElementOnlyDiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor>(WARNING, "The value ''{0}'' assigned to ''{1}'' 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
|
@Override
|
||||||
protected String makeMessageForA(@NotNull JetElement element) {
|
protected String makeMessageForA(@NotNull JetElement element) {
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package org.jetbrains.jet.lang.diagnostics;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
/**
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public class UnusedElementDiagnosticFactory<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
|
||||||
|
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String messageStub) {
|
||||||
|
return new UnusedElementDiagnosticFactory<T, A>(severity, messageStub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends PsiElement, A> UnusedElementDiagnosticFactory<T, A> create(Severity severity, String messageStub, Renderer renderer) {
|
||||||
|
return new UnusedElementDiagnosticFactory<T, A>(severity, messageStub, renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnusedElementDiagnosticFactory(Severity severity, String message, Renderer renderer) {
|
||||||
|
super(severity, message, renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected UnusedElementDiagnosticFactory(Severity severity, String message) {
|
||||||
|
super(severity, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -115,17 +115,18 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
* : modifiers "namespace" SimpleName{"."} SEMI?
|
* : modifiers "namespace" SimpleName{"."} SEMI?
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
|
PsiBuilder.Marker namespaceHeader = mark();
|
||||||
PsiBuilder.Marker firstEntry = mark();
|
PsiBuilder.Marker firstEntry = mark();
|
||||||
parseModifierList(MODIFIER_LIST, true);
|
parseModifierList(MODIFIER_LIST, true);
|
||||||
|
|
||||||
if (at(NAMESPACE_KEYWORD)) {
|
if (at(NAMESPACE_KEYWORD)) {
|
||||||
advance(); // NAMESPACE_KEYWORD
|
advance(); // NAMESPACE_KEYWORD
|
||||||
|
|
||||||
parseNamespaceName();
|
parseNamespaceName();
|
||||||
|
|
||||||
if (at(LBRACE)) {
|
if (at(LBRACE)) {
|
||||||
// Because it's blocked namespace and it will be parsed as one of top level objects
|
// Because it's blocked namespace and it will be parsed as one of top level objects
|
||||||
firstEntry.rollbackTo();
|
firstEntry.rollbackTo();
|
||||||
|
namespaceHeader.done(NAMESPACE_HEADER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +136,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
} else {
|
} else {
|
||||||
firstEntry.rollbackTo();
|
firstEntry.rollbackTo();
|
||||||
}
|
}
|
||||||
|
namespaceHeader.done(NAMESPACE_HEADER);
|
||||||
|
|
||||||
// TODO: Duplicate with parsing imports in parseToplevelDeclarations
|
// TODO: Duplicate with parsing imports in parseToplevelDeclarations
|
||||||
while (at(IMPORT_KEYWORD)) {
|
while (at(IMPORT_KEYWORD)) {
|
||||||
@@ -145,12 +147,18 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
/* SimpleName{"."} */
|
/* SimpleName{"."} */
|
||||||
private void parseNamespaceName() {
|
private void parseNamespaceName() {
|
||||||
PsiBuilder.Marker nsName = mark();
|
PsiBuilder.Marker nsName = mark();
|
||||||
expect(IDENTIFIER, "Expecting qualified name", NAMESPACE_NAME_RECOVERY_SET);
|
while (true) {
|
||||||
while (!eol() && at(DOT)) {
|
|
||||||
advance(); // DOT
|
|
||||||
expect(IDENTIFIER, "Namespace name must be a '.'-separated identifier list", NAMESPACE_NAME_RECOVERY_SET);
|
expect(IDENTIFIER, "Namespace name must be a '.'-separated identifier list", NAMESPACE_NAME_RECOVERY_SET);
|
||||||
|
if (at(DOT)) {
|
||||||
|
nsName.done(REFERENCE_EXPRESSION);
|
||||||
|
advance(); // DOT
|
||||||
|
nsName = mark();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nsName.drop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nsName.done(NAMESPACE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -378,6 +386,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
*/
|
*/
|
||||||
private JetNodeType parseNamespaceBlock() {
|
private JetNodeType parseNamespaceBlock() {
|
||||||
assert _at(NAMESPACE_KEYWORD);
|
assert _at(NAMESPACE_KEYWORD);
|
||||||
|
PsiBuilder.Marker namespaceHeader = mark();
|
||||||
advance(); // NAMESPACE_KEYWORD
|
advance(); // NAMESPACE_KEYWORD
|
||||||
|
|
||||||
if (at(LBRACE)) {
|
if (at(LBRACE)) {
|
||||||
@@ -386,6 +395,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
else {
|
else {
|
||||||
parseNamespaceName();
|
parseNamespaceName();
|
||||||
}
|
}
|
||||||
|
namespaceHeader.done(NAMESPACE_HEADER);
|
||||||
|
|
||||||
if (!at(LBRACE)) {
|
if (!at(LBRACE)) {
|
||||||
error("A namespace block in '{...}' expected");
|
error("A namespace block in '{...}' expected");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.psi;
|
|||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -26,6 +27,7 @@ public class JetAnnotatedExpression extends JetExpression {
|
|||||||
return visitor.visitAnnotatedExpression(this, data);
|
return visitor.visitAnnotatedExpression(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public JetExpression getBaseExpression() {
|
public JetExpression getBaseExpression() {
|
||||||
return findChildByClass(JetExpression.class);
|
return findChildByClass(JetExpression.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,18 +39,23 @@ public class JetNamespace extends JetNamedDeclaration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
PsiElement nameIdentifier = getNameIdentifier();
|
String name = super.getName();
|
||||||
return nameIdentifier != null ? nameIdentifier.getText() : "";
|
return name == null ? "" : name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JetNamespaceHeader getHeader() {
|
||||||
|
return (JetNamespaceHeader) findChildByType(JetNodeTypes.NAMESPACE_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiElement getNameIdentifier() {
|
public PsiElement getNameIdentifier() {
|
||||||
return findChildByType(JetNodeTypes.NAMESPACE_NAME);
|
return getHeader().getNameIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class JetNamespaceHeader extends JetElement {
|
||||||
|
public JetNamespaceHeader(@NotNull ASTNode node) {
|
||||||
|
super(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<JetSimpleNameExpression> getParentNamespaceNames() {
|
||||||
|
return findChildrenByType(JetNodeTypes.REFERENCE_EXPRESSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PsiElement getNameIdentifier() {
|
||||||
|
return findChildByType(JetTokens.IDENTIFIER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
PsiElement nameIdentifier = getNameIdentifier();
|
||||||
|
return nameIdentifier == null ? "" : nameIdentifier.getText();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.VariableAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -43,6 +44,9 @@ public class BindingContextUtils {
|
|||||||
if (descriptor instanceof VariableDescriptor) {
|
if (descriptor instanceof VariableDescriptor) {
|
||||||
return (VariableDescriptor) descriptor;
|
return (VariableDescriptor) descriptor;
|
||||||
}
|
}
|
||||||
|
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||||
|
return ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,19 +69,7 @@ public class TypeHierarchyResolver {
|
|||||||
declaration.accept(new JetVisitorVoid() {
|
declaration.accept(new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
public void visitNamespace(JetNamespace namespace) {
|
public void visitNamespace(JetNamespace namespace) {
|
||||||
String name = JetPsiUtil.safeName(namespace.getName());
|
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorPathIfNeeded(namespace, owner);
|
||||||
|
|
||||||
NamespaceDescriptorImpl namespaceDescriptor = owner.getNamespace(name);
|
|
||||||
if (namespaceDescriptor == null) {
|
|
||||||
namespaceDescriptor = new NamespaceDescriptorImpl(
|
|
||||||
owner.getOriginal(),
|
|
||||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
|
||||||
name
|
|
||||||
);
|
|
||||||
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope"));
|
|
||||||
owner.addNamespace(namespaceDescriptor);
|
|
||||||
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
|
|
||||||
}
|
|
||||||
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
|
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
|
||||||
|
|
||||||
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
|
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
|
||||||
@@ -202,6 +190,35 @@ public class TypeHierarchyResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NamespaceDescriptorImpl createNamespaceDescriptorPathIfNeeded(JetNamespace namespace, NamespaceLike owner) {
|
||||||
|
NamespaceLike currentOwner = owner;
|
||||||
|
for (JetSimpleNameExpression nameExpression : namespace.getHeader().getParentNamespaceNames()) {
|
||||||
|
currentOwner = createNamespaceDescriptorIfNeeded(null, currentOwner, JetPsiUtil.safeName(nameExpression.getReferencedName()));
|
||||||
|
context.getTrace().record(REFERENCE_TARGET, nameExpression, currentOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = JetPsiUtil.safeName(namespace.getName());
|
||||||
|
return createNamespaceDescriptorIfNeeded(namespace, currentOwner, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private NamespaceDescriptorImpl createNamespaceDescriptorIfNeeded(@Nullable JetNamespace namespace, @NotNull NamespaceLike owner, @NotNull String name) {
|
||||||
|
NamespaceDescriptorImpl namespaceDescriptor = owner.getNamespace(name);
|
||||||
|
if (namespaceDescriptor == null) {
|
||||||
|
namespaceDescriptor = new NamespaceDescriptorImpl(
|
||||||
|
owner.getOriginal(),
|
||||||
|
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
||||||
|
name
|
||||||
|
);
|
||||||
|
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope"));
|
||||||
|
owner.addNamespace(namespaceDescriptor);
|
||||||
|
if (namespace != null) {
|
||||||
|
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return namespaceDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ClassKind getClassKind(@NotNull JetClass jetClass) {
|
private ClassKind getClassKind(@NotNull JetClass jetClass) {
|
||||||
if (jetClass.isTrait()) return ClassKind.TRAIT;
|
if (jetClass.isTrait()) return ClassKind.TRAIT;
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FunctionDescriptorImpl functionDescriptor = new ExpressionAsFunctionDescriptor(scope.getContainingDeclaration(), "[for expression " + calleeExpression.getText() + "]");
|
FunctionDescriptorImpl functionDescriptor = new ExpressionAsFunctionDescriptor(scope.getContainingDeclaration(), "[for expression " + calleeExpression.getText() + "]");
|
||||||
FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, calleeType);
|
FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, calleeType, NO_RECEIVER);
|
||||||
ResolvedCallImpl<FunctionDescriptor> resolvedCall = ResolvedCallImpl.<FunctionDescriptor>create(functionDescriptor);
|
ResolvedCallImpl<FunctionDescriptor> resolvedCall = ResolvedCallImpl.<FunctionDescriptor>create(functionDescriptor);
|
||||||
resolvedCall.setReceiverArgument(call.getExplicitReceiver());
|
resolvedCall.setReceiverArgument(call.getExplicitReceiver());
|
||||||
prioritizedTasks = Collections.singletonList(new ResolutionTask<FunctionDescriptor>(
|
prioritizedTasks = Collections.singletonList(new ResolutionTask<FunctionDescriptor>(
|
||||||
|
|||||||
@@ -64,20 +64,8 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
scope = explicitReceiver.getType().getMemberScope();
|
scope = explicitReceiver.getType().getMemberScope();
|
||||||
explicitReceiver = NO_RECEIVER;
|
explicitReceiver = NO_RECEIVER;
|
||||||
}
|
}
|
||||||
doComputeTasks(scope, explicitReceiver, call, name, result, AutoCastService.NO_AUTO_CASTS);
|
doComputeTasks(scope, explicitReceiver, call, name, result, new AutoCastServiceImpl(dataFlowInfo, bindingContext));
|
||||||
|
|
||||||
List<ReceiverDescriptor> receivers;
|
|
||||||
if (explicitReceiver.exists()) {
|
|
||||||
receivers = Collections.singletonList(explicitReceiver);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
receivers = Lists.newArrayList();
|
|
||||||
scope.getImplicitReceiversHierarchy(receivers);
|
|
||||||
}
|
|
||||||
for (ReceiverDescriptor receiverToCast : receivers) {
|
|
||||||
assert receiverToCast.exists();
|
|
||||||
doComputeTasks(scope, receiverToCast, call, name, result, new AutoCastServiceImpl(dataFlowInfo, bindingContext));
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.calls.autocasts;
|
package org.jetbrains.jet.lang.resolve.calls.autocasts;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
@@ -21,7 +22,9 @@ public class AutoCastServiceImpl implements AutoCastService {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<ReceiverDescriptor> getVariantsForReceiver(@NotNull ReceiverDescriptor receiverDescriptor) {
|
public List<ReceiverDescriptor> getVariantsForReceiver(@NotNull ReceiverDescriptor receiverDescriptor) {
|
||||||
return AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverDescriptor);
|
List<ReceiverDescriptor> variants = Lists.newArrayList(AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverDescriptor));
|
||||||
|
variants.add(receiverDescriptor);
|
||||||
|
return variants;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+3
@@ -17,6 +17,9 @@ public class AutoCastUtils {
|
|||||||
|
|
||||||
private AutoCastUtils() {}
|
private AutoCastUtils() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included
|
||||||
|
*/
|
||||||
public static List<ReceiverDescriptor> getAutoCastVariants(@NotNull final BindingContext bindingContext, @NotNull final DataFlowInfo dataFlowInfo, @NotNull ReceiverDescriptor receiverToCast) {
|
public static List<ReceiverDescriptor> getAutoCastVariants(@NotNull final BindingContext bindingContext, @NotNull final DataFlowInfo dataFlowInfo, @NotNull ReceiverDescriptor receiverToCast) {
|
||||||
return receiverToCast.accept(new ReceiverDescriptorVisitor<List<ReceiverDescriptor>, Object>() {
|
return receiverToCast.accept(new ReceiverDescriptorVisitor<List<ReceiverDescriptor>, Object>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ public class DataFlowInfo {
|
|||||||
|
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
changed |= putNullability(builder, a, nullabilityOfA.refine(nullabilityOfB.invert()));
|
changed |= putNullability(builder, a, nullabilityOfA.refine(nullabilityOfB.invert()));
|
||||||
changed |= putNullability(builder, b, nullabilityOfA.refine(nullabilityOfA.invert()));
|
changed |= putNullability(builder, b, nullabilityOfB.refine(nullabilityOfA.invert()));
|
||||||
return changed ? new DataFlowInfo(ImmutableMap.copyOf(builder), typeInfo) : this;
|
return changed ? new DataFlowInfo(ImmutableMap.copyOf(builder), typeInfo) : this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -250,7 +250,8 @@ public class CompileTimeConstantResolver {
|
|||||||
if (error != null) {
|
if (error != null) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
return new StringValue(unescapedText);
|
|
||||||
|
return new StringValue(unescapedText.substring(3, unescapedText.length() - 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -299,11 +299,19 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, @NotNull PropertyDescriptor propertyDescriptor) {
|
public void addPropertyDescriptorByFieldName(@NotNull String fieldName, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
|
if (!fieldName.startsWith("$")) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
getPropertyDescriptorsByFieldNames().put(fieldName, propertyDescriptor);
|
getPropertyDescriptorsByFieldNames().put(fieldName, propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
public PropertyDescriptor getPropertyByFieldReference(@NotNull String fieldName) {
|
||||||
|
if (!fieldName.startsWith("$")) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
PropertyDescriptor descriptor = getPropertyDescriptorsByFieldNames().get(fieldName);
|
PropertyDescriptor descriptor = getPropertyDescriptorsByFieldNames().get(fieldName);
|
||||||
if (descriptor != null) return descriptor;
|
if (descriptor != null) return descriptor;
|
||||||
return super.getPropertyByFieldReference(fieldName);
|
return super.getPropertyByFieldReference(fieldName);
|
||||||
|
|||||||
+1
-5
@@ -1,7 +1,6 @@
|
|||||||
package org.jetbrains.jet.lang.types.expressions;
|
package org.jetbrains.jet.lang.types.expressions;
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.util.Function;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
@@ -14,7 +13,6 @@ import org.jetbrains.jet.lang.types.ErrorUtils;
|
|||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.ELSE_MISPLACED_IN_WHEN;
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,11 +20,9 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO
|
|||||||
*/
|
*/
|
||||||
public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetType, ExpressionTypingContext> implements ExpressionTypingInternals {
|
public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetType, ExpressionTypingContext> implements ExpressionTypingInternals {
|
||||||
|
|
||||||
private static ExpressionTypingVisitorDispatcher BASIC_DISPATCHER = new ExpressionTypingVisitorDispatcher(null);
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ExpressionTypingFacade create() {
|
public static ExpressionTypingFacade create() {
|
||||||
return BASIC_DISPATCHER;
|
return new ExpressionTypingVisitorDispatcher(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+51
-22
@@ -73,9 +73,11 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract KnownType getValue();
|
public abstract KnownType getValue();
|
||||||
|
|
||||||
|
public abstract boolean equate(TypeValue other);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UnknownType extends TypeValue {
|
private class UnknownType extends TypeValue {
|
||||||
|
|
||||||
private final TypeParameterDescriptor typeParameterDescriptor;
|
private final TypeParameterDescriptor typeParameterDescriptor;
|
||||||
private final Variance positionVariance;
|
private final Variance positionVariance;
|
||||||
@@ -87,6 +89,24 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
this.positionVariance = positionVariance;
|
this.positionVariance = positionVariance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addUpperBound(@NotNull TypeValue bound) {
|
||||||
|
addBound(bound, getLowerBounds());
|
||||||
|
super.addUpperBound(bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addLowerBound(@NotNull TypeValue bound) {
|
||||||
|
addBound(bound, getUpperBounds());
|
||||||
|
super.addLowerBound(bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBound(TypeValue bound, Set<TypeValue> oppositeBounds) {
|
||||||
|
if (oppositeBounds.contains(bound)) {
|
||||||
|
this.equate(bound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TypeParameterDescriptor getTypeParameterDescriptor() {
|
public TypeParameterDescriptor getTypeParameterDescriptor() {
|
||||||
return typeParameterDescriptor;
|
return typeParameterDescriptor;
|
||||||
@@ -139,6 +159,18 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equate(TypeValue other) {
|
||||||
|
if (other instanceof KnownType) {
|
||||||
|
KnownType knownType = (KnownType) other;
|
||||||
|
return setValue(knownType);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert other instanceof UnknownType;
|
||||||
|
mergeUnknowns((UnknownType) other, this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setValue(@NotNull KnownType value) {
|
public boolean setValue(@NotNull KnownType value) {
|
||||||
if (this.value != null) {
|
if (this.value != null) {
|
||||||
// If we have already assigned a value to this unknown,
|
// If we have already assigned a value to this unknown,
|
||||||
@@ -186,6 +218,15 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return type.toString();
|
return type.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equate(TypeValue other) {
|
||||||
|
if (other instanceof KnownType) {
|
||||||
|
KnownType knownType = (KnownType) other;
|
||||||
|
return TypeUtils.equalTypes(type, knownType.getType());
|
||||||
|
}
|
||||||
|
return other.equate(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<JetType, KnownType> knownTypes = Maps.newHashMap();
|
private final Map<JetType, KnownType> knownTypes = Maps.newHashMap();
|
||||||
@@ -233,25 +274,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
TypeValue aValue = getTypeValueFor(a);
|
TypeValue aValue = getTypeValueFor(a);
|
||||||
TypeValue bValue = getTypeValueFor(b);
|
TypeValue bValue = getTypeValueFor(b);
|
||||||
|
|
||||||
if (aValue instanceof UnknownType) {
|
return aValue.equate(bValue);
|
||||||
UnknownType aUnknown = (UnknownType) aValue;
|
|
||||||
if (bValue instanceof UnknownType) {
|
|
||||||
UnknownType bUnknown = (UnknownType) bValue;
|
|
||||||
mergeUnknowns(aUnknown, bUnknown);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!aUnknown.setValue((KnownType) bValue)) return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (bValue instanceof UnknownType) {
|
|
||||||
UnknownType bUnknown = (UnknownType) bValue;
|
|
||||||
if (!bUnknown.setValue((KnownType) aValue)) return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return TypeUtils.equalTypes(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -267,9 +290,15 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean noCorrespondingSupertype(@NotNull JetType subtype, @NotNull JetType supertype) {
|
public boolean noCorrespondingSupertype(@NotNull JetType subtype, @NotNull JetType supertype) {
|
||||||
// If some of the types is an unknown, the constraint is already generated, and we should carry on
|
// If some of the types is an unknown, the constraint must be generated, and we should carry on
|
||||||
// otherwise there can be no solution, and we should fail
|
// otherwise there can be no solution, and we should fail
|
||||||
return someUnknown(getTypeValueFor(subtype), getTypeValueFor(supertype));
|
TypeValue subTypeValue = getTypeValueFor(subtype);
|
||||||
|
TypeValue superTypeValue = getTypeValueFor(supertype);
|
||||||
|
boolean someUnknown = someUnknown(subTypeValue, superTypeValue);
|
||||||
|
if (someUnknown) {
|
||||||
|
addSubtypingConstraintOnTypeValues(subTypeValue, superTypeValue);
|
||||||
|
}
|
||||||
|
return someUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean someUnknown(TypeValue subtypeValue, TypeValue supertypeValue) {
|
private boolean someUnknown(TypeValue subtypeValue, TypeValue supertypeValue) {
|
||||||
|
|||||||
@@ -17,17 +17,20 @@ public class JetMainDetector {
|
|||||||
public static boolean hasMain(List<JetDeclaration> declarations) {
|
public static boolean hasMain(List<JetDeclaration> declarations) {
|
||||||
for (JetDeclaration declaration : declarations) {
|
for (JetDeclaration declaration : declarations) {
|
||||||
if (declaration instanceof JetNamedFunction) {
|
if (declaration instanceof JetNamedFunction) {
|
||||||
JetNamedFunction function = (JetNamedFunction) declaration;
|
if (isMain((JetNamedFunction) declaration)) return true;
|
||||||
if ("main".equals(function.getName())) {
|
}
|
||||||
List<JetParameter> parameters = function.getValueParameters();
|
}
|
||||||
if (parameters.size() == 1) {
|
return false;
|
||||||
JetTypeReference reference = parameters.get(0).getTypeReference();
|
}
|
||||||
if (reference != null && reference.getText().equals("Array<String>")) { // TODO correct check
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static boolean isMain(JetNamedFunction function) {
|
||||||
|
if ("main".equals(function.getName())) {
|
||||||
|
List<JetParameter> parameters = function.getValueParameters();
|
||||||
|
if (parameters.size() == 1) {
|
||||||
|
JetTypeReference reference = parameters.get(0).getTypeReference();
|
||||||
|
if (reference != null && reference.getText().equals("Array<String>")) { // TODO correct check
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -31,8 +31,10 @@ fun f(a : Boolean) : Unit {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[r(1)] PREV:[]
|
<START> NEXT:[v(a : Boolean)] PREV:[]
|
||||||
r(1) NEXT:[r(a)] PREV:[<START>]
|
v(a : Boolean) NEXT:[w(a)] PREV:[<START>]
|
||||||
|
w(a) NEXT:[r(1)] PREV:[v(a : Boolean)]
|
||||||
|
r(1) NEXT:[r(a)] PREV:[w(a)]
|
||||||
r(a) NEXT:[r(2)] PREV:[r(1)]
|
r(a) NEXT:[r(2)] PREV:[r(1)]
|
||||||
r(2) NEXT:[r(lng)] PREV:[r(a)]
|
r(2) NEXT:[r(lng)] PREV:[r(a)]
|
||||||
r(lng) NEXT:[r(2.lng)] PREV:[r(2)]
|
r(lng) NEXT:[r(2.lng)] PREV:[r(2)]
|
||||||
@@ -92,14 +94,18 @@ sink:
|
|||||||
fun foo(a : Boolean, b : Int) : Unit {}
|
fun foo(a : Boolean, b : Int) : Unit {}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[read (Unit)] PREV:[]
|
<START> NEXT:[v(a : Boolean)] PREV:[]
|
||||||
read (Unit) NEXT:[<END>] PREV:[<START>]
|
v(a : Boolean) NEXT:[w(a)] PREV:[<START>]
|
||||||
|
w(a) NEXT:[v(b : Int)] PREV:[v(a : Boolean)]
|
||||||
|
v(b : Int) NEXT:[w(b)] PREV:[w(a)]
|
||||||
|
w(b) NEXT:[read (Unit)] PREV:[v(b : Int)]
|
||||||
|
read (Unit) NEXT:[<END>] PREV:[w(b)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
||||||
error:
|
error:
|
||||||
<ERROR> NEXT:[] PREV:[]
|
<ERROR> NEXT:[] PREV:[]
|
||||||
sink:
|
sink:
|
||||||
<SINK> NEXT:[] PREV:[<END>]
|
<SINK> NEXT:[] PREV:[<END>]
|
||||||
=====================
|
=====================
|
||||||
== genfun ==
|
== genfun ==
|
||||||
fun genfun<T>() : Unit {}
|
fun genfun<T>() : Unit {}
|
||||||
@@ -118,12 +124,14 @@ sink:
|
|||||||
fun flfun(f : fun () : Any) : Unit {}
|
fun flfun(f : fun () : Any) : Unit {}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[read (Unit)] PREV:[]
|
<START> NEXT:[v(f : fun () : Any)] PREV:[]
|
||||||
read (Unit) NEXT:[<END>] PREV:[<START>]
|
v(f : fun () : Any) NEXT:[w(f)] PREV:[<START>]
|
||||||
|
w(f) NEXT:[read (Unit)] PREV:[v(f : fun () : Any)]
|
||||||
|
read (Unit) NEXT:[<END>] PREV:[w(f)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
||||||
error:
|
error:
|
||||||
<ERROR> NEXT:[] PREV:[]
|
<ERROR> NEXT:[] PREV:[]
|
||||||
sink:
|
sink:
|
||||||
<SINK> NEXT:[] PREV:[<END>]
|
<SINK> NEXT:[] PREV:[<END>]
|
||||||
=====================
|
=====================
|
||||||
|
|||||||
@@ -388,8 +388,10 @@ fun t8(a : Int) {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[r(1)] PREV:[]
|
<START> NEXT:[v(a : Int)] PREV:[]
|
||||||
r(1) NEXT:[r(a)] PREV:[<START>]
|
v(a : Int) NEXT:[w(a)] PREV:[<START>]
|
||||||
|
w(a) NEXT:[r(1)] PREV:[v(a : Int)]
|
||||||
|
r(1) NEXT:[r(a)] PREV:[w(a)]
|
||||||
r(a) NEXT:[r(..)] PREV:[r(1)]
|
r(a) NEXT:[r(..)] PREV:[r(1)]
|
||||||
r(..) NEXT:[r(1..a)] PREV:[r(a)]
|
r(..) NEXT:[r(1..a)] PREV:[r(a)]
|
||||||
r(1..a) NEXT:[v(i)] PREV:[r(..)]
|
r(1..a) NEXT:[v(i)] PREV:[r(..)]
|
||||||
@@ -439,8 +441,10 @@ fun t9(a : Int) {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[r(1)] PREV:[]
|
<START> NEXT:[v(a : Int)] PREV:[]
|
||||||
r(1) NEXT:[r(a)] PREV:[<START>]
|
v(a : Int) NEXT:[w(a)] PREV:[<START>]
|
||||||
|
w(a) NEXT:[r(1)] PREV:[v(a : Int)]
|
||||||
|
r(1) NEXT:[r(a)] PREV:[w(a)]
|
||||||
r(a) NEXT:[r(..)] PREV:[r(1)]
|
r(a) NEXT:[r(..)] PREV:[r(1)]
|
||||||
r(..) NEXT:[r(1..a)] PREV:[r(a)]
|
r(..) NEXT:[r(1..a)] PREV:[r(a)]
|
||||||
r(1..a) NEXT:[v(i)] PREV:[r(..)]
|
r(1..a) NEXT:[v(i)] PREV:[r(..)]
|
||||||
@@ -489,8 +493,10 @@ fun t10(a : Int) {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[r(1)] PREV:[]
|
<START> NEXT:[v(a : Int)] PREV:[]
|
||||||
r(1) NEXT:[r(a)] PREV:[<START>]
|
v(a : Int) NEXT:[w(a)] PREV:[<START>]
|
||||||
|
w(a) NEXT:[r(1)] PREV:[v(a : Int)]
|
||||||
|
r(1) NEXT:[r(a)] PREV:[w(a)]
|
||||||
r(a) NEXT:[r(..)] PREV:[r(1)]
|
r(a) NEXT:[r(..)] PREV:[r(1)]
|
||||||
r(..) NEXT:[r(1..a)] PREV:[r(a)]
|
r(..) NEXT:[r(1..a)] PREV:[r(a)]
|
||||||
r(1..a) NEXT:[v(i)] PREV:[r(..)]
|
r(1..a) NEXT:[v(i)] PREV:[r(..)]
|
||||||
@@ -747,8 +753,10 @@ fun doSmth(i: Int) {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[read (Unit)] PREV:[]
|
<START> NEXT:[v(i: Int)] PREV:[]
|
||||||
read (Unit) NEXT:[<END>] PREV:[<START>]
|
v(i: Int) NEXT:[w(i)] PREV:[<START>]
|
||||||
|
w(i) NEXT:[read (Unit)] PREV:[v(i: Int)]
|
||||||
|
read (Unit) NEXT:[<END>] PREV:[w(i)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
||||||
error:
|
error:
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ sink:
|
|||||||
fun doSmth(i: Int) {}
|
fun doSmth(i: Int) {}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[read (Unit)] PREV:[]
|
<START> NEXT:[v(i: Int)] PREV:[]
|
||||||
read (Unit) NEXT:[<END>] PREV:[<START>]
|
v(i: Int) NEXT:[w(i)] PREV:[<START>]
|
||||||
|
w(i) NEXT:[read (Unit)] PREV:[v(i: Int)]
|
||||||
|
read (Unit) NEXT:[<END>] PREV:[w(i)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
||||||
error:
|
error:
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ fun t1(b: Boolean) {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[v(var u: String)] PREV:[]
|
<START> NEXT:[v(b: Boolean)] PREV:[]
|
||||||
v(var u: String) NEXT:[r(b)] PREV:[<START>]
|
v(b: Boolean) NEXT:[w(b)] PREV:[<START>]
|
||||||
|
w(b) NEXT:[v(var u: String)] PREV:[v(b: Boolean)]
|
||||||
|
v(var u: String) NEXT:[r(b)] PREV:[w(b)]
|
||||||
r(b) NEXT:[jf(l2)] PREV:[v(var u: String)]
|
r(b) NEXT:[jf(l2)] PREV:[v(var u: String)]
|
||||||
jf(l2) NEXT:[read (Unit), r("s")] PREV:[r(b)]
|
jf(l2) NEXT:[read (Unit), r("s")] PREV:[r(b)]
|
||||||
r("s") NEXT:[w(u)] PREV:[jf(l2)]
|
r("s") NEXT:[w(u)] PREV:[jf(l2)]
|
||||||
@@ -63,45 +65,49 @@ fun t2(b: Boolean) {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[v(val i = 3)] PREV:[]
|
<START> NEXT:[v(b: Boolean)] PREV:[]
|
||||||
v(val i = 3) NEXT:[r(3)] PREV:[<START>]
|
v(b: Boolean) NEXT:[w(b)] PREV:[<START>]
|
||||||
r(3) NEXT:[w(i)] PREV:[v(val i = 3)]
|
w(b) NEXT:[v(val i = 3)] PREV:[v(b: Boolean)]
|
||||||
w(i) NEXT:[r(b)] PREV:[r(3)]
|
v(val i = 3) NEXT:[r(3)] PREV:[w(b)]
|
||||||
r(b) NEXT:[jf(l2)] PREV:[w(i)]
|
r(3) NEXT:[w(i)] PREV:[v(val i = 3)]
|
||||||
jf(l2) NEXT:[read (Unit), ret l1] PREV:[r(b)]
|
w(i) NEXT:[r(b)] PREV:[r(3)]
|
||||||
ret l1 NEXT:[<END>] PREV:[jf(l2)]
|
r(b) NEXT:[jf(l2)] PREV:[w(i)]
|
||||||
* jmp(l3) NEXT:[r(i)] PREV:[]
|
jf(l2) NEXT:[read (Unit), ret l1] PREV:[r(b)]
|
||||||
|
ret l1 NEXT:[<END>] PREV:[jf(l2)]
|
||||||
|
* jmp(l3) NEXT:[r(i)] PREV:[]
|
||||||
l2:
|
l2:
|
||||||
read (Unit) NEXT:[r(i)] PREV:[jf(l2)]
|
read (Unit) NEXT:[r(i)] PREV:[jf(l2)]
|
||||||
l3:
|
l3:
|
||||||
r(i) NEXT:[r(doSmth)] PREV:[read (Unit)]
|
r(i) NEXT:[r(doSmth)] PREV:[read (Unit)]
|
||||||
r(doSmth) NEXT:[r(doSmth(i))] PREV:[r(i)]
|
r(doSmth) NEXT:[r(doSmth(i))] PREV:[r(i)]
|
||||||
r(doSmth(i)) NEXT:[r(i)] PREV:[r(doSmth)]
|
r(doSmth(i)) NEXT:[r(i)] PREV:[r(doSmth)]
|
||||||
r(i) NEXT:[r(i is Int)] PREV:[r(doSmth(i))]
|
r(i) NEXT:[r(i is Int)] PREV:[r(doSmth(i))]
|
||||||
r(i is Int) NEXT:[jf(l4)] PREV:[r(i)]
|
r(i is Int) NEXT:[jf(l4)] PREV:[r(i)]
|
||||||
jf(l4) NEXT:[read (Unit), ret l1] PREV:[r(i is Int)]
|
jf(l4) NEXT:[read (Unit), ret l1] PREV:[r(i is Int)]
|
||||||
ret l1 NEXT:[<END>] PREV:[jf(l4)]
|
ret l1 NEXT:[<END>] PREV:[jf(l4)]
|
||||||
* jmp(l5) NEXT:[<END>] PREV:[]
|
* jmp(l5) NEXT:[<END>] PREV:[]
|
||||||
l4:
|
l4:
|
||||||
read (Unit) NEXT:[<END>] PREV:[jf(l4)]
|
read (Unit) NEXT:[<END>] PREV:[jf(l4)]
|
||||||
l1:
|
l1:
|
||||||
l5:
|
l5:
|
||||||
<END> NEXT:[<SINK>] PREV:[ret l1, ret l1, read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[ret l1, ret l1, read (Unit)]
|
||||||
error:
|
error:
|
||||||
<ERROR> NEXT:[] PREV:[]
|
<ERROR> NEXT:[] PREV:[]
|
||||||
sink:
|
sink:
|
||||||
<SINK> NEXT:[] PREV:[<END>]
|
<SINK> NEXT:[] PREV:[<END>]
|
||||||
=====================
|
=====================
|
||||||
== doSmth ==
|
== doSmth ==
|
||||||
fun doSmth(s: String) {}
|
fun doSmth(s: String) {}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[read (Unit)] PREV:[]
|
<START> NEXT:[v(s: String)] PREV:[]
|
||||||
read (Unit) NEXT:[<END>] PREV:[<START>]
|
v(s: String) NEXT:[w(s)] PREV:[<START>]
|
||||||
|
w(s) NEXT:[read (Unit)] PREV:[v(s: String)]
|
||||||
|
read (Unit) NEXT:[<END>] PREV:[w(s)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
||||||
error:
|
error:
|
||||||
<ERROR> NEXT:[] PREV:[]
|
<ERROR> NEXT:[] PREV:[]
|
||||||
sink:
|
sink:
|
||||||
<SINK> NEXT:[] PREV:[<END>]
|
<SINK> NEXT:[] PREV:[<END>]
|
||||||
=====================
|
=====================
|
||||||
|
|||||||
@@ -18,57 +18,61 @@ fun lazyBooleans(a : Boolean, b : Boolean) : Unit {
|
|||||||
}
|
}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[r(a)] PREV:[]
|
<START> NEXT:[v(a : Boolean)] PREV:[]
|
||||||
r(a) NEXT:[jf(l2)] PREV:[<START>]
|
v(a : Boolean) NEXT:[w(a)] PREV:[<START>]
|
||||||
jf(l2) NEXT:[r(2), r(1)] PREV:[r(a)]
|
w(a) NEXT:[v(b : Boolean)] PREV:[v(a : Boolean)]
|
||||||
r(1) NEXT:[jmp(l3)] PREV:[jf(l2)]
|
v(b : Boolean) NEXT:[w(b)] PREV:[w(a)]
|
||||||
jmp(l3) NEXT:[r(3)] PREV:[r(1)]
|
w(b) NEXT:[r(a)] PREV:[v(b : Boolean)]
|
||||||
|
r(a) NEXT:[jf(l2)] PREV:[w(b)]
|
||||||
|
jf(l2) NEXT:[r(2), r(1)] PREV:[r(a)]
|
||||||
|
r(1) NEXT:[jmp(l3)] PREV:[jf(l2)]
|
||||||
|
jmp(l3) NEXT:[r(3)] PREV:[r(1)]
|
||||||
l2:
|
l2:
|
||||||
r(2) NEXT:[r(3)] PREV:[jf(l2)]
|
r(2) NEXT:[r(3)] PREV:[jf(l2)]
|
||||||
l3:
|
l3:
|
||||||
r(3) NEXT:[r(a)] PREV:[jmp(l3), r(2)]
|
r(3) NEXT:[r(a)] PREV:[jmp(l3), r(2)]
|
||||||
r(a) NEXT:[jf(l4)] PREV:[r(3)]
|
r(a) NEXT:[jf(l4)] PREV:[r(3)]
|
||||||
jf(l4) NEXT:[jf(l5), r(b)] PREV:[r(a)]
|
jf(l4) NEXT:[jf(l5), r(b)] PREV:[r(a)]
|
||||||
r(b) NEXT:[jf(l5)] PREV:[jf(l4)]
|
r(b) NEXT:[jf(l5)] PREV:[jf(l4)]
|
||||||
l4:
|
l4:
|
||||||
jf(l5) NEXT:[r(6), r(5)] PREV:[jf(l4), r(b)]
|
jf(l5) NEXT:[r(6), r(5)] PREV:[jf(l4), r(b)]
|
||||||
r(5) NEXT:[jmp(l6)] PREV:[jf(l5)]
|
r(5) NEXT:[jmp(l6)] PREV:[jf(l5)]
|
||||||
jmp(l6) NEXT:[r(7)] PREV:[r(5)]
|
jmp(l6) NEXT:[r(7)] PREV:[r(5)]
|
||||||
l5:
|
l5:
|
||||||
r(6) NEXT:[r(7)] PREV:[jf(l5)]
|
r(6) NEXT:[r(7)] PREV:[jf(l5)]
|
||||||
l6:
|
l6:
|
||||||
r(7) NEXT:[r(a)] PREV:[jmp(l6), r(6)]
|
r(7) NEXT:[r(a)] PREV:[jmp(l6), r(6)]
|
||||||
r(a) NEXT:[jt(l7)] PREV:[r(7)]
|
r(a) NEXT:[jt(l7)] PREV:[r(7)]
|
||||||
jt(l7) NEXT:[r(b), jf(l8)] PREV:[r(a)]
|
jt(l7) NEXT:[r(b), jf(l8)] PREV:[r(a)]
|
||||||
r(b) NEXT:[jf(l8)] PREV:[jt(l7)]
|
r(b) NEXT:[jf(l8)] PREV:[jt(l7)]
|
||||||
l7:
|
l7:
|
||||||
jf(l8) NEXT:[r(9), r(8)] PREV:[jt(l7), r(b)]
|
jf(l8) NEXT:[r(9), r(8)] PREV:[jt(l7), r(b)]
|
||||||
r(8) NEXT:[jmp(l9)] PREV:[jf(l8)]
|
r(8) NEXT:[jmp(l9)] PREV:[jf(l8)]
|
||||||
jmp(l9) NEXT:[r(10)] PREV:[r(8)]
|
jmp(l9) NEXT:[r(10)] PREV:[r(8)]
|
||||||
l8:
|
l8:
|
||||||
r(9) NEXT:[r(10)] PREV:[jf(l8)]
|
r(9) NEXT:[r(10)] PREV:[jf(l8)]
|
||||||
l9:
|
l9:
|
||||||
r(10) NEXT:[r(a)] PREV:[jmp(l9), r(9)]
|
r(10) NEXT:[r(a)] PREV:[jmp(l9), r(9)]
|
||||||
r(a) NEXT:[jf(l10)] PREV:[r(10)]
|
r(a) NEXT:[jf(l10)] PREV:[r(10)]
|
||||||
jf(l10) NEXT:[read (Unit), r(11)] PREV:[r(a)]
|
jf(l10) NEXT:[read (Unit), r(11)] PREV:[r(a)]
|
||||||
r(11) NEXT:[jmp(l11)] PREV:[jf(l10)]
|
r(11) NEXT:[jmp(l11)] PREV:[jf(l10)]
|
||||||
jmp(l11) NEXT:[r(12)] PREV:[r(11)]
|
jmp(l11) NEXT:[r(12)] PREV:[r(11)]
|
||||||
l10:
|
l10:
|
||||||
read (Unit) NEXT:[r(12)] PREV:[jf(l10)]
|
read (Unit) NEXT:[r(12)] PREV:[jf(l10)]
|
||||||
l11:
|
l11:
|
||||||
r(12) NEXT:[r(a)] PREV:[jmp(l11), read (Unit)]
|
r(12) NEXT:[r(a)] PREV:[jmp(l11), read (Unit)]
|
||||||
r(a) NEXT:[jf(l12)] PREV:[r(12)]
|
r(a) NEXT:[jf(l12)] PREV:[r(12)]
|
||||||
jf(l12) NEXT:[r(13), read (Unit)] PREV:[r(a)]
|
jf(l12) NEXT:[r(13), read (Unit)] PREV:[r(a)]
|
||||||
read (Unit) NEXT:[jmp(l13)] PREV:[jf(l12)]
|
read (Unit) NEXT:[jmp(l13)] PREV:[jf(l12)]
|
||||||
jmp(l13) NEXT:[r(14)] PREV:[read (Unit)]
|
jmp(l13) NEXT:[r(14)] PREV:[read (Unit)]
|
||||||
l12:
|
l12:
|
||||||
r(13) NEXT:[r(14)] PREV:[jf(l12)]
|
r(13) NEXT:[r(14)] PREV:[jf(l12)]
|
||||||
l13:
|
l13:
|
||||||
r(14) NEXT:[<END>] PREV:[jmp(l13), r(13)]
|
r(14) NEXT:[<END>] PREV:[jmp(l13), r(13)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[r(14)]
|
<END> NEXT:[<SINK>] PREV:[r(14)]
|
||||||
error:
|
error:
|
||||||
<ERROR> NEXT:[] PREV:[]
|
<ERROR> NEXT:[] PREV:[]
|
||||||
sink:
|
sink:
|
||||||
<SINK> NEXT:[] PREV:[<END>]
|
<SINK> NEXT:[] PREV:[<END>]
|
||||||
=====================
|
=====================
|
||||||
|
|||||||
@@ -80,8 +80,10 @@ sink:
|
|||||||
fun doSmth(i: Int) {}
|
fun doSmth(i: Int) {}
|
||||||
---------------------
|
---------------------
|
||||||
l0:
|
l0:
|
||||||
<START> NEXT:[read (Unit)] PREV:[]
|
<START> NEXT:[v(i: Int)] PREV:[]
|
||||||
read (Unit) NEXT:[<END>] PREV:[<START>]
|
v(i: Int) NEXT:[w(i)] PREV:[<START>]
|
||||||
|
w(i) NEXT:[read (Unit)] PREV:[v(i: Int)]
|
||||||
|
read (Unit) NEXT:[<END>] PREV:[w(i)]
|
||||||
l1:
|
l1:
|
||||||
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
<END> NEXT:[<SINK>] PREV:[read (Unit)]
|
||||||
error:
|
error:
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ abstract class B3(i: Int) {
|
|||||||
this(): this(1)
|
this(): this(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo(c: B3) {
|
fun foo(<!UNUSED_PARAMETER!>c<!>: B3) {
|
||||||
val <!UNUSED_VARIABLE!>a<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
|
val <!UNUSED_VARIABLE!>a<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
|
||||||
val <!UNUSED_VARIABLE!>b<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
|
val <!UNUSED_VARIABLE!>b<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
|
||||||
}
|
}
|
||||||
@@ -15,18 +15,18 @@ fun text() {
|
|||||||
bar2 <!TYPE_MISMATCH!>{<!CANNOT_INFER_PARAMETER_TYPE!>it<!> => it}<!>
|
bar2 <!TYPE_MISMATCH!>{<!CANNOT_INFER_PARAMETER_TYPE!>it<!> => it}<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bar(f : fun (Int, Int) : Int) {}
|
fun bar(<!UNUSED_PARAMETER!>f<!> : fun (Int, Int) : Int) {}
|
||||||
fun bar1(f : fun (Int) : Int) {}
|
fun bar1(<!UNUSED_PARAMETER!>f<!> : fun (Int) : Int) {}
|
||||||
fun bar2(f : fun () : Int) {}
|
fun bar2(<!UNUSED_PARAMETER!>f<!> : fun () : Int) {}
|
||||||
|
|
||||||
fun String.to(dest : String) {
|
fun String.to(<!UNUSED_PARAMETER!>dest<!> : String) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.on(predicate : fun (s : URI) : Boolean) : URI {
|
fun String.on(<!UNUSED_PARAMETER!>predicate<!> : fun (s : URI) : Boolean) : URI {
|
||||||
return URI(this)
|
return URI(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
class URI(val body : Any) {
|
class URI(val body : Any) {
|
||||||
fun to(dest : String) {}
|
fun to(<!UNUSED_PARAMETER!>dest<!> : String) {}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ class AClass() {
|
|||||||
|
|
||||||
val x : Any? = 1
|
val x : Any? = 1
|
||||||
|
|
||||||
fun Any?.vars(a: Any?) : Int {
|
fun Any?.vars(<!UNUSED_PARAMETER!>a<!>: Any?) : Int {
|
||||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
|
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
|
||||||
if (ns.y is Int) {
|
if (ns.y is Int) {
|
||||||
b = <!UNUSED_VALUE!>ns.y<!>
|
b = <!UNUSED_VALUE!>ns.y<!>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
fun foo(u : Unit) : Int = 1
|
fun foo(<!UNUSED_PARAMETER!>u<!> : Unit) : Int = 1
|
||||||
|
|
||||||
fun test() : Int {
|
fun test() : Int {
|
||||||
foo(<!TYPE_MISMATCH!>1<!>)
|
foo(<!TYPE_MISMATCH!>1<!>)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
class A() {
|
class A() {
|
||||||
fun equals(a : Any?) : Boolean = false
|
fun equals(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean = false
|
||||||
}
|
}
|
||||||
|
|
||||||
class B() {
|
class B() {
|
||||||
fun equals(a : Any?) : Boolean? = false
|
fun equals(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean? = false
|
||||||
}
|
}
|
||||||
|
|
||||||
class C() {
|
class C() {
|
||||||
fun equals(a : Any?) : Int = 0
|
fun equals(<!UNUSED_PARAMETER!>a<!> : Any?) : Int = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun f(): Unit {
|
fun f(): Unit {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class C {
|
class C {
|
||||||
|
|
||||||
fun f (a : Boolean, b : Boolean) {
|
fun f (<!UNUSED_PARAMETER!>a<!> : Boolean, <!UNUSED_PARAMETER!>b<!> : Boolean) {
|
||||||
@b (while (true)
|
@b (while (true)
|
||||||
@a {
|
@a {
|
||||||
<!NOT_A_LOOP_LABEL!>break@f<!>
|
<!NOT_A_LOOP_LABEL!>break@f<!>
|
||||||
@@ -25,7 +25,7 @@ class C {
|
|||||||
<!NOT_A_LOOP_LABEL!>break@f<!>
|
<!NOT_A_LOOP_LABEL!>break@f<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun containsBreak(a: String?, b: String?) {
|
fun containsBreak(a: String?, <!UNUSED_PARAMETER!>b<!>: String?) {
|
||||||
while (a == null) {
|
while (a == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
// http://youtrack.jetbrains.net/issue/KT-424
|
// http://youtrack.jetbrains.net/issue/KT-424
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
<!CONFLICTING_OVERLOADS!>fun a(a: Int): Int<!> = 0
|
<!CONFLICTING_OVERLOADS!>fun a(<!UNUSED_PARAMETER!>a<!>: Int): Int<!> = 0
|
||||||
|
|
||||||
<!CONFLICTING_OVERLOADS!>fun a(a: Int)<!> {
|
<!CONFLICTING_OVERLOADS!>fun a(<!UNUSED_PARAMETER!>a<!>: Int)<!> {
|
||||||
}
|
}
|
||||||
|
|
||||||
<!CONFLICTING_OVERLOADS!>fun b()<!> {
|
<!CONFLICTING_OVERLOADS!>fun b()<!> {
|
||||||
@@ -14,17 +14,17 @@ class A {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace deepSpace {
|
namespace deepSpace {
|
||||||
<!CONFLICTING_OVERLOADS!>fun c(s: String)<!> {
|
<!CONFLICTING_OVERLOADS!>fun c(<!UNUSED_PARAMETER!>s<!>: String)<!> {
|
||||||
}
|
}
|
||||||
|
|
||||||
<!CONFLICTING_OVERLOADS!>fun c(s: String)<!> {
|
<!CONFLICTING_OVERLOADS!>fun c(<!UNUSED_PARAMETER!>s<!>: String)<!> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class B {
|
class B {
|
||||||
<!CONFLICTING_OVERLOADS!>fun d(s: String)<!> {
|
<!CONFLICTING_OVERLOADS!>fun d(<!UNUSED_PARAMETER!>s<!>: String)<!> {
|
||||||
}
|
}
|
||||||
|
|
||||||
<!CONFLICTING_OVERLOADS!>fun d(s: String)<!> {
|
<!CONFLICTING_OVERLOADS!>fun d(<!UNUSED_PARAMETER!>s<!>: String)<!> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,9 @@ namespace ns3 {
|
|||||||
// check same rules apply for ext functions
|
// check same rules apply for ext functions
|
||||||
|
|
||||||
namespace extensionFunctions {
|
namespace extensionFunctions {
|
||||||
<!CONFLICTING_OVERLOADS!>fun Int.qwe(a: Float)<!> = 1
|
<!CONFLICTING_OVERLOADS!>fun Int.qwe(<!UNUSED_PARAMETER!>a<!>: Float)<!> = 1
|
||||||
|
|
||||||
<!CONFLICTING_OVERLOADS!>fun Int.qwe(a: Float)<!> = 2
|
<!CONFLICTING_OVERLOADS!>fun Int.qwe(<!UNUSED_PARAMETER!>a<!>: Float)<!> = 2
|
||||||
|
|
||||||
fun Int.rty() = 3
|
fun Int.rty() = 3
|
||||||
|
|
||||||
@@ -95,4 +95,3 @@ namespace constructorVsFun {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
val x = ""
|
val x = ""
|
||||||
|
|
||||||
fun bar(x : Int = <!TYPE_MISMATCH!>""<!>, y : Int = <!TYPE_MISMATCH!>x<!>, z : String = <!UNRESOLVED_REFERENCE!>y<!>) {
|
fun bar(<!UNUSED_PARAMETER!>x<!> : Int = <!TYPE_MISMATCH!>""<!>, <!UNUSED_PARAMETER!>y<!> : Int = <!TYPE_MISMATCH!>x<!>, <!UNUSED_PARAMETER!>z<!> : String = <!UNRESOLVED_REFERENCE!>y<!>) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
fun Int?.optint() : Unit {}
|
fun Int?.optint() : Unit {}
|
||||||
val Int?.optval : Unit = ()
|
val Int?.optval : Unit = ()
|
||||||
|
|
||||||
fun <T, E> T.foo(x : E, y : A) : T {
|
fun <T, E> T.foo(<!UNUSED_PARAMETER!>x<!> : E, y : A) : T {
|
||||||
y.plus(1)
|
y.plus(1)
|
||||||
y plus 1
|
y plus 1
|
||||||
y + 1.0
|
y + 1.0
|
||||||
@@ -15,7 +15,7 @@ fun <T, E> T.foo(x : E, y : A) : T {
|
|||||||
|
|
||||||
class A
|
class A
|
||||||
|
|
||||||
fun A.plus(a : Any) {
|
fun A.plus(<!UNUSED_PARAMETER!>a<!> : Any) {
|
||||||
|
|
||||||
1.foo()
|
1.foo()
|
||||||
true.<!NONE_APPLICABLE!>foo<!>()
|
true.<!NONE_APPLICABLE!>foo<!>()
|
||||||
@@ -23,11 +23,11 @@ fun A.plus(a : Any) {
|
|||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun A.plus(a : Int) {
|
fun A.plus(<!UNUSED_PARAMETER!>a<!> : Int) {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> T.minus(t : T) : Int = 1
|
fun <T> T.minus(<!UNUSED_PARAMETER!>t<!> : T) : Int = 1
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val <!UNUSED_VARIABLE!>y<!> = 1.abs
|
val <!UNUSED_VARIABLE!>y<!> = 1.abs
|
||||||
@@ -41,15 +41,15 @@ fun Int.foo() = this
|
|||||||
|
|
||||||
namespace null_safety {
|
namespace null_safety {
|
||||||
|
|
||||||
fun parse(cmd: String): Command? { return null }
|
fun parse(<!UNUSED_PARAMETER!>cmd<!>: String): Command? { return null }
|
||||||
class Command() {
|
class Command() {
|
||||||
// fun equals(other : Any?) : Boolean
|
// fun equals(other : Any?) : Boolean
|
||||||
val foo : Int = 0
|
val foo : Int = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Any.equals(other : Any?) : Boolean = true
|
fun Any.equals(<!UNUSED_PARAMETER!>other<!> : Any?) : Boolean = true
|
||||||
fun Any?.equals1(other : Any?) : Boolean = true
|
fun Any?.equals1(<!UNUSED_PARAMETER!>other<!> : Any?) : Boolean = true
|
||||||
fun Any.equals2(other : Any?) : Boolean = true
|
fun Any.equals2(<!UNUSED_PARAMETER!>other<!> : Any?) : Boolean = true
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ fun main(args : Array<String>) {
|
|||||||
|
|
||||||
fun f() : fun Int.() : Unit = {}
|
fun f() : fun Int.() : Unit = {}
|
||||||
|
|
||||||
fun main1(args : Array<String>) {
|
fun main1() {
|
||||||
1.{Int.() => 1}();
|
1.{Int.() => 1}();
|
||||||
{1}()
|
{1}()
|
||||||
{(x : Int) => x}(1)
|
{(x : Int) => x}(1)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// A generic funciton is always less specific than a non-generic one
|
// A generic funciton is always less specific than a non-generic one
|
||||||
fun foo<T>(t : T) : Unit {}
|
fun foo<T>(<!UNUSED_PARAMETER!>t<!> : T) : Unit {}
|
||||||
fun foo(i : Int) : Int = 1
|
fun foo(<!UNUSED_PARAMETER!>i<!> : Int) : Int = 1
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
foo(1) : Int
|
foo(1) : Int
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
fun ff(<!UNUSED_PARAMETER!>a<!>: String) = 1
|
||||||
fun ff(a: String) = 1
|
|
||||||
|
|
||||||
fun gg() {
|
fun gg() {
|
||||||
val a: String? = ""
|
val a: String? = ""
|
||||||
@@ -8,4 +7,3 @@ fun gg() {
|
|||||||
ff(a)
|
ff(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ open class B() {
|
|||||||
|
|
||||||
class C() : B() {
|
class C() : B() {
|
||||||
var x = 4
|
var x = 4
|
||||||
fun foo(c: C) {
|
fun foo(<!UNUSED_PARAMETER!>c<!>: C) {
|
||||||
this.x = 34
|
this.x = 34
|
||||||
this.b = 123
|
this.b = 123
|
||||||
super.b = 23
|
super.b = 23
|
||||||
@@ -17,7 +17,7 @@ class C() : B() {
|
|||||||
<!VARIABLE_EXPECTED!>getInt()<!> = 12
|
<!VARIABLE_EXPECTED!>getInt()<!> = 12
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo1(c: C) {
|
fun foo1(<!UNUSED_PARAMETER!>c<!>: C) {
|
||||||
<!VAL_REASSIGNMENT!>super.c<!> = 34
|
<!VAL_REASSIGNMENT!>super.c<!> = 34
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class D() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cannotBe(var i: Int) {
|
fun cannotBe(var <!UNUSED_PARAMETER!>i<!>: Int) {
|
||||||
<!UNRESOLVED_REFERENCE!>z<!> = 30;
|
<!UNRESOLVED_REFERENCE!>z<!> = 30;
|
||||||
<!VARIABLE_EXPECTED!>()<!> = ();
|
<!VARIABLE_EXPECTED!>()<!> = ();
|
||||||
|
|
||||||
@@ -47,18 +47,18 @@ fun cannotBe(var i: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun canBe(var i: Int, val j: Int) {
|
fun canBe(var i: Int, val j: Int) {
|
||||||
(i: Int) = 36
|
(i: Int) = <!UNUSED_VALUE!>36<!>
|
||||||
(@label i) = 34
|
(@label i) = <!UNUSED_VALUE!>34<!>
|
||||||
|
|
||||||
(<!VAL_REASSIGNMENT!>j<!>: Int) = 36
|
(<!VAL_REASSIGNMENT!>j<!>: Int) = <!UNUSED_VALUE!>36<!>
|
||||||
(@label j) = 34 //repeat for j
|
(@label j) = <!UNUSED_VALUE!>34<!> //repeat for j
|
||||||
|
|
||||||
val a = A()
|
val a = A()
|
||||||
(@ a.a) = 3894
|
(@ a.a) = 3894
|
||||||
}
|
}
|
||||||
|
|
||||||
fun canBe2(val j: Int) {
|
fun canBe2(val j: Int) {
|
||||||
(@label <!VAL_REASSIGNMENT!>j<!>) = 34
|
(@label <!VAL_REASSIGNMENT!>j<!>) = <!UNUSED_VALUE!>34<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
fun foo(a : Int = 1, b : String = "abc") {
|
fun foo(<!UNUSED_PARAMETER!>a<!> : Int = 1, <!UNUSED_PARAMETER!>b<!> : String = "abc") {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bar(x : Int = 1, y : Int = 1, z : String) {
|
fun bar(<!UNUSED_PARAMETER!>x<!> : Int = 1, <!UNUSED_PARAMETER!>y<!> : Int = 1, <!UNUSED_PARAMETER!>z<!> : String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// +JDK
|
// +JDK
|
||||||
|
|
||||||
// Fixpoint generic in Java: Enum<T extends Enum<T>>
|
// Fixpoint generic in Java: Enum<T extends Enum<T>>
|
||||||
fun test(a : annotation.RetentionPolicy) {
|
fun test(<!UNUSED_PARAMETER!>a<!> : annotation.RetentionPolicy) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9,14 +9,14 @@ fun test() {
|
|||||||
java.util.Collections.emptyList()
|
java.util.Collections.emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test(a : java.lang.Comparable<Int>) {
|
fun test(<!UNUSED_PARAMETER!>a<!> : java.lang.Comparable<Int>) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test(a : java.util.ArrayList<Int>) {
|
fun test(<!UNUSED_PARAMETER!>a<!> : java.util.ArrayList<Int>) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test(a : java.lang.Class<Int>) {
|
fun test(<!UNUSED_PARAMETER!>a<!> : java.lang.Class<Int>) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import java.lang.Comparable as Com
|
|||||||
|
|
||||||
val l : List<in Int> = ArrayList<Int>()
|
val l : List<in Int> = ArrayList<Int>()
|
||||||
|
|
||||||
fun test(l : java.util.List<Int>) {
|
fun test(<!UNUSED_PARAMETER!>l<!> : java.util.List<Int>) {
|
||||||
val <!UNUSED_VARIABLE!>x<!> : java.<!UNRESOLVED_REFERENCE!>List<!>
|
val <!UNUSED_VARIABLE!>x<!> : java.<!UNRESOLVED_REFERENCE!>List<!>
|
||||||
val <!UNUSED_VARIABLE!>y<!> : java.util.List<Int>
|
val <!UNUSED_VARIABLE!>y<!> : java.util.List<Int>
|
||||||
val <!UNUSED_VARIABLE!>b<!> : java.lang.Object
|
val <!UNUSED_VARIABLE!>b<!> : java.lang.Object
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace example;
|
namespace example;
|
||||||
|
|
||||||
fun any(a : Any) {}
|
fun any(<!UNUSED_PARAMETER!>a<!> : Any) {}
|
||||||
|
|
||||||
fun notAnExpression() {
|
fun notAnExpression() {
|
||||||
any(<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>) // not an expression
|
any(<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>) // not an expression
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class C<T>() {
|
|||||||
fun foo() : T <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
fun foo() : T <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo(c: C<Int>) {}
|
fun foo(<!UNUSED_PARAMETER!>c<!>: C<Int>) {}
|
||||||
fun bar<T>() : C<T> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
fun bar<T>() : C<T> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||||
|
|
||||||
fun main(args : Array<String>) {
|
fun main(args : Array<String>) {
|
||||||
|
|||||||
+6
-6
@@ -1,7 +1,7 @@
|
|||||||
namespace uninitialized_reassigned_variables
|
namespace uninitialized_reassigned_variables
|
||||||
|
|
||||||
fun doSmth(s: String) {}
|
fun doSmth(<!UNUSED_PARAMETER!>s<!>: String) {}
|
||||||
fun doSmth(i: Int) {}
|
fun doSmth(<!UNUSED_PARAMETER!>i<!>: Int) {}
|
||||||
|
|
||||||
// ------------------------------------------------
|
// ------------------------------------------------
|
||||||
// uninitialized variables
|
// uninitialized variables
|
||||||
@@ -54,9 +54,9 @@ fun t2() {
|
|||||||
class A() {}
|
class A() {}
|
||||||
|
|
||||||
fun t4(a: A, val b: A, var c: A) {
|
fun t4(a: A, val b: A, var c: A) {
|
||||||
<!VAL_REASSIGNMENT!>a<!> = A()
|
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>A()<!>
|
||||||
<!VAL_REASSIGNMENT!>b<!> = A()
|
<!VAL_REASSIGNMENT!>b<!> = <!UNUSED_VALUE!>A()<!>
|
||||||
c = A()
|
c = <!UNUSED_VALUE!>A()<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------
|
// ------------------------------------------------
|
||||||
@@ -191,7 +191,7 @@ class AnonymousInitializers(var a: String, val b: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun reassignFunParams(val a: Int) {
|
fun reassignFunParams(val a: Int) {
|
||||||
<!VAL_REASSIGNMENT!>a<!> = 1
|
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>1<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Open(a: Int, w: Int) {}
|
open class Open(a: Int, w: Int) {}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ fun t3() : Any {
|
|||||||
<!UNREACHABLE_CODE!>1<!>
|
<!UNREACHABLE_CODE!>1<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun t4(a : Boolean) : Int {
|
fun t4(<!UNUSED_PARAMETER!>a<!> : Boolean) : Int {
|
||||||
do {
|
do {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ fun t4(a : Boolean) : Int {
|
|||||||
<!UNREACHABLE_CODE!>1<!>
|
<!UNREACHABLE_CODE!>1<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun t4break(a : Boolean) : Int {
|
fun t4break(<!UNUSED_PARAMETER!>a<!> : Boolean) : Int {
|
||||||
do {
|
do {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ fun nullIsNotNothing() : Unit {
|
|||||||
fail()
|
fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun returnInWhile(a: Int) {
|
fun returnInWhile(<!UNUSED_PARAMETER!>a<!>: Int) {
|
||||||
do {return}
|
do {return}
|
||||||
while (<!UNREACHABLE_CODE!>1 > a<!>)
|
while (<!UNREACHABLE_CODE!>1 > a<!>)
|
||||||
}
|
}
|
||||||
@@ -28,4 +28,4 @@ fun testUnresolved() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo1(i: Int) {}
|
fun foo1(<!UNUSED_PARAMETER!>i<!>: Int) {}
|
||||||
@@ -86,8 +86,8 @@ class MyTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doSmth(s: String) {}
|
fun doSmth(<!UNUSED_PARAMETER!>s<!>: String) {}
|
||||||
fun doSmth(a: Any) {}
|
fun doSmth(<!UNUSED_PARAMETER!>a<!>: Any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testInnerFunctions() {
|
fun testInnerFunctions() {
|
||||||
@@ -139,4 +139,4 @@ fun testBackingFieldsNotMarked() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doSmth(i : Int) {}
|
fun doSmth(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fun v(x : Int, y : String, vararg f : Long) {}
|
fun v(<!UNUSED_PARAMETER!>x<!> : Int, <!UNUSED_PARAMETER!>y<!> : String, vararg <!UNUSED_PARAMETER!>f<!> : Long) {}
|
||||||
fun v1(vararg f : fun (Int) : Unit) {}
|
fun v1(vararg <!UNUSED_PARAMETER!>f<!> : fun (Int) : Unit) {}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
v(1, "")
|
v(1, "")
|
||||||
|
|||||||
@@ -19,17 +19,17 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
|
|||||||
|
|
||||||
//Arrays copy example
|
//Arrays copy example
|
||||||
class Array<T>(val length : Int, val t : T) {
|
class Array<T>(val length : Int, val t : T) {
|
||||||
fun get(index : Int) : T { return t }
|
fun get(<!UNUSED_PARAMETER!>index<!> : Int) : T { return t }
|
||||||
fun set(index : Int, value : T) { /* ... */ }
|
fun set(<!UNUSED_PARAMETER!>index<!> : Int, <!UNUSED_PARAMETER!>value<!> : T) { /* ... */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copy1(from : Array<Any>, to : Array<Any>) {}
|
fun copy1(<!UNUSED_PARAMETER!>from<!> : Array<Any>, <!UNUSED_PARAMETER!>to<!> : Array<Any>) {}
|
||||||
|
|
||||||
fun copy2(from : Array<out Any>, to : Array<in Any>) {}
|
fun copy2(<!UNUSED_PARAMETER!>from<!> : Array<out Any>, <!UNUSED_PARAMETER!>to<!> : Array<in Any>) {}
|
||||||
|
|
||||||
fun <T> copy3(from : Array<out T>, to : Array<in T>) {}
|
fun <T> copy3(<!UNUSED_PARAMETER!>from<!> : Array<out T>, <!UNUSED_PARAMETER!>to<!> : Array<in T>) {}
|
||||||
|
|
||||||
fun copy4(from : Array<out Number>, to : Array<in Int>) {}
|
fun copy4(<!UNUSED_PARAMETER!>from<!> : Array<out Number>, <!UNUSED_PARAMETER!>to<!> : Array<in Int>) {}
|
||||||
|
|
||||||
fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) {
|
fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) {
|
||||||
copy1(<!TYPE_MISMATCH!>ints<!>, any)
|
copy1(<!TYPE_MISMATCH!>ints<!>, any)
|
||||||
|
|||||||
+4
-4
@@ -1,11 +1,11 @@
|
|||||||
class A() {
|
class A() {
|
||||||
fun plus(i : Int) {}
|
fun plus(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||||
fun minus() {}
|
fun minus() {}
|
||||||
fun contains(a : Any?) : Boolean = true
|
fun contains(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun A.div(i : Int) {}
|
fun A.div(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||||
fun A?.times(i : Int) {}
|
fun A?.times(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||||
|
|
||||||
fun test(x : Int?, a : A?) {
|
fun test(x : Int?, a : A?) {
|
||||||
x<!UNSAFE_CALL!>.<!>plus(1)
|
x<!UNSAFE_CALL!>.<!>plus(1)
|
||||||
|
|||||||
+2
-2
@@ -7,6 +7,6 @@ val b : Foo = Foo()
|
|||||||
val a1 = b.compareTo(2)
|
val a1 = b.compareTo(2)
|
||||||
|
|
||||||
class Foo() {
|
class Foo() {
|
||||||
fun compareTo(other : Byte) : Int = 0
|
fun compareTo(<!UNUSED_PARAMETER!>other<!> : Byte) : Int = 0
|
||||||
fun compareTo(other : Char) : Int = 0
|
fun compareTo(<!UNUSED_PARAMETER!>other<!> : Char) : Int = 0
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
fun foo(u : Unit) : Int = 1
|
fun foo(<!UNUSED_PARAMETER!>u<!> : Unit) : Int = 1
|
||||||
|
|
||||||
fun test() : Int {
|
fun test() : Int {
|
||||||
foo(<!TYPE_MISMATCH!>1<!>)
|
foo(<!TYPE_MISMATCH!>1<!>)
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
fun foo(a : Any) {}
|
fun foo(<!UNUSED_PARAMETER!>a<!> : Any) {}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
foo(object {});
|
foo(object {});
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
fun foo1() : fun (Int) : Int = { (x: Int) => x }
|
fun foo1() : fun (Int) : Int = { (x: Int) => x }
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val <!UNUSED_VARIABLE!>h<!> : fun (Int) : Int = foo1();
|
val h : fun (Int) : Int = foo1();
|
||||||
h(1)
|
h(1)
|
||||||
val <!UNUSED_VARIABLE!>m<!> : fun (Int) : Int = {(a : Int) => 1}//foo1()
|
val m : fun (Int) : Int = {(a : Int) => 1}//foo1()
|
||||||
m(1)
|
m(1)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
fun set(key : String, value : String) {
|
fun set(<!UNUSED_PARAMETER!>key<!> : String, <!UNUSED_PARAMETER!>value<!> : String) {
|
||||||
val a : String? = ""
|
val a : String? = ""
|
||||||
when (a) {
|
when (a) {
|
||||||
"" => a<!UNSAFE_CALL!>.<!>get(0)
|
"" => a<!UNSAFE_CALL!>.<!>get(0)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Command() {}
|
class Command() {}
|
||||||
|
|
||||||
fun parse(cmd: String): Command? { return null }
|
fun parse(<!UNUSED_PARAMETER!>cmd<!>: String): Command? { return null }
|
||||||
|
|
||||||
fun Any.equals(other : Any?) : Boolean = this === other
|
fun Any.equals(other : Any?) : Boolean = this === other
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Point() {
|
|||||||
|
|
||||||
class G<T>() {}
|
class G<T>() {}
|
||||||
|
|
||||||
fun f<T>(expression : T) : G<out T> = G<T>
|
fun f<T>(<!UNUSED_PARAMETER!>expression<!> : T) : G<out T> = G<T>
|
||||||
|
|
||||||
|
|
||||||
fun foo() : G<Point> {
|
fun foo() : G<Point> {
|
||||||
@@ -13,7 +13,7 @@ fun foo() : G<Point> {
|
|||||||
|
|
||||||
class Out<out T>() {}
|
class Out<out T>() {}
|
||||||
|
|
||||||
fun fout<T>(expression : T) : Out<out T> = Out<T>
|
fun fout<T>(<!UNUSED_PARAMETER!>expression<!> : T) : Out<out T> = Out<T>
|
||||||
|
|
||||||
fun fooout() : Out<Point> {
|
fun fooout() : Out<Point> {
|
||||||
val p = Point();
|
val p = Point();
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ class Foo(var bar : Int, var barr : Int, var barrr : Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this(var bar : Int) : this(1, 1, 1) {
|
this(var bar : Int) : this(1, 1, 1) {
|
||||||
bar = 1
|
bar = <!UNUSED_VALUE!>1<!>
|
||||||
this.bar
|
this.bar
|
||||||
1 : Int
|
1 : Int
|
||||||
val <!UNUSED_VARIABLE!>a<!> : Int =1
|
val <!UNUSED_VARIABLE!>a<!> : Int =1
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
fun Any.equals(other : Any?) : Boolean = true
|
fun Any.equals(<!UNUSED_PARAMETER!>other<!> : Any?) : Boolean = true
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
open class Foo {}
|
open class Foo {}
|
||||||
open class Bar {}
|
open class Bar {}
|
||||||
|
|
||||||
fun <T : Bar, T1> foo(x : Int) {}
|
fun <T : Bar, T1> foo(<!UNUSED_PARAMETER!>x<!> : Int) {}
|
||||||
fun <T1, T : Foo> foo(x : Long) {}
|
fun <T1, T : Foo> foo(<!UNUSED_PARAMETER!>x<!> : Long) {}
|
||||||
|
|
||||||
fun f(): Unit {
|
fun f(): Unit {
|
||||||
foo<<!UPPER_BOUND_VIOLATED!>Int<!>, Int>(1)
|
foo<<!UPPER_BOUND_VIOLATED!>Int<!>, Int>(1)
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
//KT-609 Analyze not only local variables, but function parameters as well in 'unused values' analysis
|
||||||
|
|
||||||
|
namespace kt609
|
||||||
|
|
||||||
|
fun test(var a: Int) {
|
||||||
|
a = <!UNUSED_VALUE!>324<!> //should be an 'unused value' warning here
|
||||||
|
}
|
||||||
|
|
||||||
|
class C() {
|
||||||
|
fun foo(<!UNUSED_PARAMETER!>s<!>: String) {} //should be an 'unused variable' warning
|
||||||
|
}
|
||||||
|
|
||||||
|
open class A() {
|
||||||
|
open fun foo(s : String) {} //should not be a warning
|
||||||
|
}
|
||||||
|
|
||||||
|
class B() : A() {
|
||||||
|
final override fun foo(s : String) {} //should not be a warning
|
||||||
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
class Foo() {}
|
class Foo() {}
|
||||||
|
|
||||||
fun Any.equals(other : Any?) : Boolean = true
|
fun Any.equals(<!UNUSED_PARAMETER!>other<!> : Any?) : Boolean = true
|
||||||
fun Any?.equals1(other : Any?) : Boolean = true
|
fun Any?.equals1(<!UNUSED_PARAMETER!>other<!> : Any?) : Boolean = true
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// KT-128 Support passing only the last closure if all the other parameters have default values
|
// KT-128 Support passing only the last closure if all the other parameters have default values
|
||||||
|
|
||||||
fun div(c : String = "", f : fun()) {}
|
fun div(<!UNUSED_PARAMETER!>c<!> : String = "", <!UNUSED_PARAMETER!>f<!> : fun()) {}
|
||||||
fun f() {
|
fun f() {
|
||||||
div { // Nothing passed, but could have been...
|
div { // Nothing passed, but could have been...
|
||||||
// ...
|
// ...
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// KT-174 Nullability info for extension function receivers
|
||||||
|
// +JDK
|
||||||
|
trait Tree {}
|
||||||
|
|
||||||
|
fun Any?.TreeValue() : Tree {
|
||||||
|
if (this is Tree) return this
|
||||||
|
throw Exception()
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// KT-201 Allow to call extension with nullable receiver with a '.'
|
||||||
|
// +JDK
|
||||||
|
|
||||||
|
fun <T : Any> T?.npe() : T = if (this == null) throw NullPointerException() else this
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val i : Int? = 1
|
||||||
|
i.npe() // error!
|
||||||
|
}
|
||||||
@@ -36,13 +36,13 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyArray() {
|
class MyArray() {
|
||||||
fun get(i: Int): Int = 1
|
fun get(<!UNUSED_PARAMETER!>i<!>: Int): Int = 1
|
||||||
fun set(i: Int, value: Int): Int = 1
|
fun set(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>value<!>: Int): Int = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyArray1() {
|
class MyArray1() {
|
||||||
fun get(i: Int): Int = 1
|
fun get(<!UNUSED_PARAMETER!>i<!>: Int): Int = 1
|
||||||
fun set(i: Int, value: Int) {}
|
fun set(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>value<!>: Int) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyNumber() {
|
class MyNumber() {
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ fun test() {
|
|||||||
attributes["href"] = "1" // inference fails, but it shouldn't
|
attributes["href"] = "1" // inference fails, but it shouldn't
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <K, V> java.util.Map<K, V>.set(key : K, value : V) {}//= this.put(key, value)
|
fun <K, V> java.util.Map<K, V>.set(<!UNUSED_PARAMETER!>key<!> : K, <!UNUSED_PARAMETER!>value<!> : V) {}//= this.put(key, value)
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
// KT-282 Nullability in extension functions and in binary calls
|
// KT-282 Nullability in extension functions and in binary calls
|
||||||
|
|
||||||
class Set {
|
class Set {
|
||||||
fun contains(x : Int) : Boolean = true
|
fun contains(<!UNUSED_PARAMETER!>x<!> : Int) : Boolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Set?.plus(x : Int) : Int = 1
|
fun Set?.plus(<!UNUSED_PARAMETER!>x<!> : Int) : Int = 1
|
||||||
|
|
||||||
fun Int?.contains(x : Int) : Boolean = false
|
fun Int?.contains(<!UNUSED_PARAMETER!>x<!> : Int) : Boolean = false
|
||||||
|
|
||||||
fun f(): Unit {
|
fun f(): Unit {
|
||||||
var set : Set? = null
|
var set : Set? = null
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.*
|
|||||||
fun attributes() : Map<String, String> = HashMap() // Should be inferred;
|
fun attributes() : Map<String, String> = HashMap() // Should be inferred;
|
||||||
val attributes : Map<String, String> = HashMap() // Should be inferred;
|
val attributes : Map<String, String> = HashMap() // Should be inferred;
|
||||||
|
|
||||||
fun foo(m : Map<String, String>) {}
|
fun foo(<!UNUSED_PARAMETER!>m<!> : Map<String, String>) {}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
foo(HashMap())
|
foo(HashMap())
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// KT-312 Nullability problem when a nullable version of a generic type is returned
|
||||||
|
|
||||||
|
fun <T> Array<out T>.safeGet(index : Int) : T? {
|
||||||
|
return if (index < size) this[index] else null
|
||||||
|
}
|
||||||
|
|
||||||
|
val args : Array<String> = Array<String>(1)
|
||||||
|
val name : String = <!TYPE_MISMATCH!>args.safeGet<String>(0)<!> // No error, must be type mismatch
|
||||||
|
val name1 : String? = args.safeGet(0)
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ fun <T : java.lang.Comparable<T>> List<T>.sort() {
|
|||||||
Collections.sort(this) // Error here
|
Collections.sort(this) // Error here
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> List<T>.plus(other : List<T>) : List<T> {
|
fun <T> List<T>.plus(<!UNUSED_PARAMETER!>other<!> : List<T>) : List<T> {
|
||||||
val result = ArrayList(this)
|
val result = ArrayList(this)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ val g : fun() : Unit = <!TYPE_MISMATCH!>{ (): Int => 42 }<!>
|
|||||||
val h : fun() : Unit = { doSmth() }
|
val h : fun() : Unit = { doSmth() }
|
||||||
|
|
||||||
fun doSmth(): Int = 42
|
fun doSmth(): Int = 42
|
||||||
fun doSmth(a: String) {}
|
fun doSmth(<!UNUSED_PARAMETER!>a<!>: String) {}
|
||||||
|
|
||||||
val testIt : fun(Any) : Unit = {
|
val testIt : fun(Any) : Unit = {
|
||||||
if (it is String) {
|
if (it is String) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// KT-398 Internal error when property initializes with function
|
||||||
|
|
||||||
|
class X<T>() {
|
||||||
|
val check = { (a : Any) => a is T }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
if(X<String>().check(10)) return "fail"
|
||||||
|
if(!X<String>().check("lala")) return "fail"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// KT-399 Type argument inference not implemented for CALL_EXPRESSION
|
// KT-399 Type argument inference not implemented for CALL_EXPRESSION
|
||||||
|
|
||||||
fun <T> getSameTypeChecker(obj: T) : Function1<Any,Boolean> {
|
fun <T> getSameTypeChecker(<!UNUSED_PARAMETER!>obj<!>: T) : Function1<Any,Boolean> {
|
||||||
return { (a : Any) => a is T }
|
return { (a : Any) => a is T }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fun f() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fun invoker(gen : fun() : Int) : Int = 0
|
fun invoker(<!UNUSED_PARAMETER!>gen<!> : fun() : Int) : Int = 0
|
||||||
|
|
||||||
//more tests
|
//more tests
|
||||||
fun t1() {
|
fun t1() {
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
inline fun run1<T>(body : fun() : T) : T = body()
|
inline fun run1<T>(body : fun() : T) : T = body()
|
||||||
|
|
||||||
fun main1(args : Array<String>) {
|
fun main1(<!UNUSED_PARAMETER!>args<!> : Array<String>) {
|
||||||
run1 @l{ 1 } // should not be an error
|
run1 @l{ 1 } // should not be an error
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ fun testFunny() {
|
|||||||
val <!UNUSED_VARIABLE!>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 <T> funny2(<!UNUSED_PARAMETER!>f<!> : fun(t : T) : T) : T <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||||
|
|
||||||
fun testFunny2() {
|
fun testFunny2() {
|
||||||
val <!UNUSED_VARIABLE!>a<!> : Int = funny2 {it}
|
val <!UNUSED_VARIABLE!>a<!> : Int = funny2 {it}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ fun foo() {
|
|||||||
doSmth(<!UNINITIALIZED_VARIABLE!>a<!>) //error
|
doSmth(<!UNINITIALIZED_VARIABLE!>a<!>) //error
|
||||||
doSmth(a) //no repeat error
|
doSmth(a) //no repeat error
|
||||||
}
|
}
|
||||||
fun doSmth(i: Int) {}
|
fun doSmth(<!UNUSED_PARAMETER!>i<!>: Int) {}
|
||||||
@@ -6,4 +6,4 @@ fun test() {
|
|||||||
attributes["href"] = "1" // inference fails, but it shouldn't
|
attributes["href"] = "1" // inference fails, but it shouldn't
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <K, V> java.util.Map<K, V>.set(key : K, value : V) {}//= this.put(key, value)
|
fun <K, V> java.util.Map<K, V>.set(<!UNUSED_PARAMETER!>key<!> : K, <!UNUSED_PARAMETER!>value<!> : V) {}//= this.put(key, value)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// KT-524 sure() returns T
|
||||||
|
// +JDK
|
||||||
|
|
||||||
|
namespace StringBuilder
|
||||||
|
|
||||||
|
import java.lang.StringBuilder
|
||||||
|
|
||||||
|
//import std.io.*
|
||||||
|
//import java.io.*
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
}
|
||||||
|
|
||||||
|
val Int.bd : StringBuilder get() = StringBuilder(this.toString())
|
||||||
|
fun StringBuilder.plus(other : StringBuilder) : StringBuilder = this.append(other).sure1() // !!!
|
||||||
|
|
||||||
|
fun <T : Any> T?.sure1() : T { return if (this != null) this else throw NullPointerException() }
|
||||||
@@ -88,5 +88,5 @@ fun t7() : Int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doSmth(i: Int) {
|
fun doSmth(<!UNUSED_PARAMETER!>i<!>: Int) {
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//KT-597 Type inference failed
|
||||||
|
// +JDK
|
||||||
|
|
||||||
|
fun <T> Array<T>?.get(i: Int) : T {
|
||||||
|
if (this != null)
|
||||||
|
return this.get(i) // <- inferred type is Any? but &T was excepted
|
||||||
|
else throw NullPointerException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Int?.inc() : Int {
|
||||||
|
if (this != null)
|
||||||
|
return this.inc()
|
||||||
|
else
|
||||||
|
throw NullPointerException()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
var i : Int? = 10
|
||||||
|
var <!UNUSED_VARIABLE!>i_inc<!> = <!UNUSED_CHANGED_VALUE!>i++<!> // <- expected Int?, but returns Any?
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// KT-604 Internal frontend error
|
||||||
|
|
||||||
|
trait ChannelPipeline {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DefaultChannelPipeline() : ChannelPipeline {
|
||||||
|
}
|
||||||
|
|
||||||
|
trait ChannelPipelineFactory{
|
||||||
|
fun getPipeline() : ChannelPipeline
|
||||||
|
}
|
||||||
|
|
||||||
|
class StandardPipelineFactory(val config: fun ChannelPipeline.():Unit) : ChannelPipelineFactory {
|
||||||
|
override fun getPipeline() : ChannelPipeline {
|
||||||
|
val pipeline = DefaultChannelPipeline()
|
||||||
|
pipeline.config ()
|
||||||
|
return pipeline
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
namespace lol
|
namespace lol
|
||||||
|
|
||||||
class B() {
|
class B() {
|
||||||
fun plusAssign(other : B) : String {
|
fun plusAssign(<!UNUSED_PARAMETER!>other<!> : B) : String {
|
||||||
return "s"
|
return "s"
|
||||||
}
|
}
|
||||||
fun minusAssign(other : B) : String {
|
fun minusAssign(<!UNUSED_PARAMETER!>other<!> : B) : String {
|
||||||
return "s"
|
return "s"
|
||||||
}
|
}
|
||||||
fun modAssign(other : B) : String {
|
fun modAssign(<!UNUSED_PARAMETER!>other<!> : B) : String {
|
||||||
return "s"
|
return "s"
|
||||||
}
|
}
|
||||||
fun divAssign(other : B) : String {
|
fun divAssign(<!UNUSED_PARAMETER!>other<!> : B) : String {
|
||||||
return "s"
|
return "s"
|
||||||
}
|
}
|
||||||
fun timesAssign(other : B) : String {
|
fun timesAssign(<!UNUSED_PARAMETER!>other<!> : B) : String {
|
||||||
return "s"
|
return "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace kt629
|
|||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
var p = "yeah"
|
var p = "yeah"
|
||||||
fun mod(other : A) : A {
|
fun mod(<!UNUSED_PARAMETER!>other<!> : A) : A {
|
||||||
return A();
|
return A();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// KT-630 Bad type inference
|
||||||
|
val x = "lala".sure()
|
||||||
|
val s : String = x
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// KT-668 Failed to resolve generic parameter
|
||||||
|
open class A()
|
||||||
|
open class B() : A() {
|
||||||
|
fun b(): B = B()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class C() {
|
||||||
|
fun a<T>(x: fun(T):T, y: T): T {
|
||||||
|
return x(x(y))
|
||||||
|
}
|
||||||
|
|
||||||
|
val x: B = a({it.b()}, B())
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// KT-691 Allow to create nested namespaces with dot delimiter
|
||||||
|
namespace foo.bar.buz
|
||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
|
fun f(<!UNUSED_PARAMETER!>p<!>: Int): Int {
|
||||||
fun f(p: Int): Int {
|
|
||||||
val <!NAME_SHADOWING!>p<!> = 2
|
val <!NAME_SHADOWING!>p<!> = 2
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
fun f(i: Int) {
|
fun f(<!UNUSED_PARAMETER!>i<!>: Int) {
|
||||||
for (j in 1..100) {
|
for (j in 1..100) {
|
||||||
{
|
{
|
||||||
var <!NAME_SHADOWING!>i<!> = 12
|
var <!NAME_SHADOWING!>i<!> = 12
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user