isStatement() fixed for returned expressions
This commit is contained in:
@@ -80,6 +80,11 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
|
||||
statements.add(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStatementRecord(@NotNull JetElement statement) {
|
||||
statements.remove(statement);
|
||||
}
|
||||
|
||||
public void setToplevelScope(JetScope toplevelScope) {
|
||||
this.toplevelScope = toplevelScope;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ public class BindingTrace {
|
||||
|
||||
}
|
||||
|
||||
public void removeStatementRecord(@NotNull JetElement statement) {
|
||||
|
||||
}
|
||||
|
||||
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression) {
|
||||
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class JetTypeInferrer {
|
||||
|
||||
@NotNull
|
||||
public JetType getFunctionReturnType(@NotNull JetScope outerScope, JetFunction function, FunctionDescriptor functionDescriptor) {
|
||||
Map<JetElement, JetType> typeMap = getReturnedExpressions(outerScope, function, functionDescriptor);
|
||||
Map<JetElement, JetType> typeMap = collectReturnedExpressions(outerScope, function, functionDescriptor);
|
||||
Collection<JetType> types = typeMap.values();
|
||||
return types.isEmpty() ? JetStandardClasses.getNothingType() : semanticServices.getTypeChecker().commonSupertype(types);
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public class JetTypeInferrer {
|
||||
}
|
||||
|
||||
public void checkFunctionReturnType(@NotNull JetScope outerScope, @NotNull JetFunction function, @NotNull FunctionDescriptor functionDescriptor) {
|
||||
Map<JetElement, JetType> typeMap = getReturnedExpressions(outerScope, function, functionDescriptor);
|
||||
Map<JetElement, JetType> typeMap = collectReturnedExpressions(outerScope, function, functionDescriptor);
|
||||
if (typeMap.isEmpty()) {
|
||||
return; // The function returns Nothing
|
||||
}
|
||||
@@ -315,7 +315,7 @@ public class JetTypeInferrer {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<JetElement, JetType> getReturnedExpressions(JetScope outerScope, JetFunction function, FunctionDescriptor functionDescriptor) {
|
||||
private Map<JetElement, JetType> collectReturnedExpressions(JetScope outerScope, JetFunction function, FunctionDescriptor functionDescriptor) {
|
||||
JetExpression bodyExpression = function.getBodyExpression();
|
||||
assert bodyExpression != null;
|
||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, semanticServices);
|
||||
@@ -326,6 +326,7 @@ public class JetTypeInferrer {
|
||||
Map<JetElement,JetType> typeMap = new HashMap<JetElement, JetType>();
|
||||
for (JetExpression returnedExpression : returnedExpressions) {
|
||||
JetType cachedType = getCachedType(returnedExpression);
|
||||
trace.removeStatementRecord(returnedExpression);
|
||||
if (cachedType != null) {
|
||||
typeMap.put(returnedExpression, cachedType);
|
||||
}
|
||||
@@ -882,7 +883,7 @@ public class JetTypeInferrer {
|
||||
JetType iteratorType = iteratorResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
|
||||
boolean hasNextFunctionSupported = checkHasNextFunctionSupport(reportErrorsOn, iteratorType);
|
||||
boolean hasNextPropertySupported = checkHasNextPropertySupport(reportErrorsOn, iteratorType);
|
||||
if (hasNextFunctionSupported && hasNextPropertySupported) {
|
||||
if (hasNextFunctionSupported && hasNextPropertySupported && !ErrorUtils.isErrorType(iteratorType)) {
|
||||
// TODO : overload resolution rules impose priorities here???
|
||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext()' property");
|
||||
}
|
||||
@@ -1596,5 +1597,10 @@ public class JetTypeInferrer {
|
||||
public void recordStatement(@NotNull JetElement statement) {
|
||||
originalTrace.recordStatement(statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStatementRecord(@NotNull JetElement statement) {
|
||||
originalTrace.removeStatementRecord(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import java.util.*;
|
||||
|
||||
class NotRange1 {
|
||||
|
||||
}
|
||||
@@ -73,4 +75,7 @@ fun test() {
|
||||
for (i in <error>new NotRange7()</error>);
|
||||
for (i in new Range0());
|
||||
for (i in new Range1());
|
||||
|
||||
for (i in (new ArrayList() : List));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import org.jetbrains.jet.resolve.JetResolveTest;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -12,6 +11,6 @@ public class JetLightProjectDescriptor extends DefaultLightProjectDescriptor {
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return JetResolveTest.jdkFromIdeaHome();
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -26,6 +28,10 @@ public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Sdk jdkFromIdeaHome() {
|
||||
return new JavaSdkImpl().createJdk("JDK", "idea/testData/mockJDK-1.7/jre", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return getTestDataPathBase();
|
||||
@@ -39,6 +45,11 @@ public abstract class JetTestCaseBase extends LightDaemonAnalyzerTestCase {
|
||||
return new File(PathManager.getResourceRoot(JetTestCaseBase.class, "/org/jetbrains/jet/JetTestCaseBase.class")).getParentFile().getParentFile().getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test" + name;
|
||||
|
||||
@@ -3,13 +3,13 @@ package org.jetbrains.jet.resolve;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadResolutionResult;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
@@ -112,11 +112,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
public static Sdk jdkFromIdeaHome() {
|
||||
return new JavaSdkImpl().createJdk("JDK", "idea/testData/mockJDK-1.7/jre", true);
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
private static String getHomeDirectory() {
|
||||
|
||||
Reference in New Issue
Block a user