removed check for 'hasNext' val in frontend
This commit is contained in:
@@ -212,7 +212,6 @@ public interface Errors {
|
||||
DiagnosticFactory1<JetSimpleNameExpression, ClassifierDescriptor> NO_CLASS_OBJECT = DiagnosticFactory1.create(ERROR);
|
||||
SimpleDiagnosticFactory<PsiElement> NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR);
|
||||
|
||||
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR);
|
||||
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_MISSING = SimpleDiagnosticFactory.create(ERROR);
|
||||
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR);
|
||||
SimpleDiagnosticFactory<JetExpression> HAS_NEXT_MUST_BE_READABLE = SimpleDiagnosticFactory.create(ERROR);
|
||||
|
||||
-2
@@ -228,8 +228,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(NO_CLASS_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a class object", NAME);
|
||||
MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified");
|
||||
|
||||
MAP.put(HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY,
|
||||
"An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
|
||||
MAP.put(HAS_NEXT_MISSING, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
|
||||
MAP.put(HAS_NEXT_FUNCTION_AMBIGUITY, "Function 'iterator().hasNext()' is ambiguous for this expression");
|
||||
MAP.put(HAS_NEXT_MUST_BE_READABLE, "The 'iterator().hasNext' property of the loop range must be readable");
|
||||
|
||||
+2
-27
@@ -327,17 +327,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType iteratorType = iteratorFunction.getReturnType();
|
||||
FunctionDescriptor hasNextFunction = checkHasNextFunctionSupport(loopRangeExpression, iteratorType, context);
|
||||
boolean hasNextFunctionSupported = hasNextFunction != null;
|
||||
VariableDescriptor hasNextProperty = checkHasNextPropertySupport(loopRangeExpression, iteratorType, context);
|
||||
boolean hasNextPropertySupported = hasNextProperty != null;
|
||||
if (hasNextFunctionSupported && hasNextPropertySupported && !ErrorUtils.isErrorType(iteratorType)) {
|
||||
// TODO : overload resolution rules impose priorities here???
|
||||
context.trace.report(HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY.on(loopRangeExpression));
|
||||
}
|
||||
else if (!hasNextFunctionSupported && !hasNextPropertySupported) {
|
||||
if (!hasNextFunctionSupported) {
|
||||
context.trace.report(HAS_NEXT_MISSING.on(loopRangeExpression));
|
||||
}
|
||||
else {
|
||||
context.trace.record(LOOP_RANGE_HAS_NEXT, loopRange.getExpression(), hasNextFunctionSupported ? hasNextFunction : hasNextProperty);
|
||||
context.trace.record(LOOP_RANGE_HAS_NEXT, loopRange.getExpression(), hasNextFunction);
|
||||
}
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> nextResolutionResults = context.resolveExactSignature(new TransientReceiver(iteratorType), Name.identifier("next"), Collections.<JetType>emptyList());
|
||||
@@ -388,25 +382,6 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
return hasNextResolutionResults.getResultingCall().getResultingDescriptor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static VariableDescriptor checkHasNextPropertySupport(@NotNull JetExpression loopRange, @NotNull JetType iteratorType, ExpressionTypingContext context) {
|
||||
VariableDescriptor hasNextProperty = DescriptorUtils.filterNonExtensionProperty(iteratorType.getMemberScope().getProperties(Name.identifier("hasNext")));
|
||||
if (hasNextProperty == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
JetType hasNextReturnType = hasNextProperty.getType();
|
||||
if (hasNextReturnType == null) {
|
||||
// TODO : accessibility
|
||||
context.trace.report(HAS_NEXT_MUST_BE_READABLE.on(loopRange));
|
||||
}
|
||||
else if (!isBoolean(hasNextReturnType)) {
|
||||
context.trace.report(HAS_NEXT_PROPERTY_TYPE_MISMATCH.on(loopRange, hasNextReturnType));
|
||||
}
|
||||
}
|
||||
return hasNextProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetTypeInfo visitTryExpression(JetTryExpression expression, ExpressionTypingContext context) {
|
||||
JetExpression tryBlock = expression.getTryBlock();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
fun <T : Any> T?.iterator() = object {
|
||||
var hasNext = this@iterator != null
|
||||
private set
|
||||
fun hasNext() = hasNext
|
||||
|
||||
fun next() : T {
|
||||
if (hasNext) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class NotRange1() {
|
||||
@@ -82,12 +81,11 @@ fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRa
|
||||
for (i in <!NEXT_MISSING!>notRange3<!>);
|
||||
for (i in <!HAS_NEXT_MISSING!>notRange4<!>);
|
||||
for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange5<!>);
|
||||
for (i in <!HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY!>notRange6<!>);
|
||||
for (i in notRange6);
|
||||
for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange7<!>);
|
||||
for (i in <!HAS_NEXT_MISSING!>notRange8<!>);
|
||||
for (i in range0);
|
||||
for (i in range1);
|
||||
|
||||
for (i in (ArrayList<Int>() : List<Int>));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ inline fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> {
|
||||
fun <T : Any> T?.iterator() = object {
|
||||
var hasNext = this@iterator != null
|
||||
private set
|
||||
fun hasNext() = hasNext
|
||||
|
||||
fun next() : T {
|
||||
if (hasNext) {
|
||||
|
||||
@@ -71,7 +71,7 @@ fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRa
|
||||
for (i in <error>notRange3</error>);
|
||||
for (i in <error>notRange4</error>);
|
||||
for (i in <error>notRange5</error>);
|
||||
for (i in <error>notRange6</error>);
|
||||
for (i in notRange6);
|
||||
for (i in <error>notRange7</error>);
|
||||
for (i in range0);
|
||||
for (i in range1);
|
||||
|
||||
+1
-2
@@ -12,8 +12,7 @@ class SimpleEnumerator {
|
||||
}
|
||||
|
||||
class SimpleEnumeratorWrapper(private val enumerator: SimpleEnumerator) {
|
||||
val hasNext: Boolean
|
||||
get() = enumerator.hasMoreElements()
|
||||
fun hasNext(): Boolean = enumerator.hasMoreElements()
|
||||
|
||||
fun next() = enumerator.getNext()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user