提交 9b0a9b71 编写于 作者: A Andrey Breslav

isStatement() fixed for returned expressions

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