fixed bug: 'isStatement' for function body == 'hasBlockBody'

not vice versa
This commit is contained in:
Svetlana Isakova
2013-09-30 17:24:03 +04:00
parent fa8ca4e781
commit a3f9cef354
9 changed files with 25 additions and 9 deletions
@@ -193,7 +193,7 @@ public class ExpressionTypingServices {
? context.replaceExpectedType(NO_EXPECTED_TYPE)
: context;
expressionTypingFacade.getTypeInfo(bodyExpression, newContext, !blockBody);
expressionTypingFacade.getTypeInfo(bodyExpression, newContext, blockBody);
}
@NotNull
@@ -247,7 +247,7 @@ public class ExpressionTypingServices {
ExpressionTypingContext context = ExpressionTypingContext.newContext(
this, trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, ExpressionPosition.FREE
);
JetTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, !function.hasBlockBody());
JetTypeInfo typeInfo = expressionTypingFacade.getTypeInfo(bodyExpression, context, function.hasBlockBody());
trace.record(STATEMENT, bodyExpression, false);
JetType type = typeInfo.getType();
@@ -25,7 +25,7 @@ open class A(val init: String) {
public var backingField : Int = 0
get() = $backingField.myInc
set(s) = $backingField = s
set(s) { $backingField = s }
}
@@ -0,0 +1,11 @@
fun foo1() = <!EXPRESSION_EXPECTED!>while (b()) {}<!>
fun foo2() = <!EXPRESSION_EXPECTED!>for (<!UNUSED_PARAMETER!>i<!> in <!ITERATOR_MISSING!>10<!>) {}<!>
fun foo3() = when (b()) {
true -> 1
else -> 0
}
fun b(): Boolean = true
@@ -42,8 +42,8 @@ fun box() : Int {
//More tests
fun test1() = while(true) {}
fun test2(): Unit = while(true) {}
fun test1() { while(true) {} }
fun test2(): Unit { while(true) {} }
fun testCoercionToUnit() {
val <!UNUSED_VARIABLE!>simple<!>: ()-> Unit = {
@@ -3,7 +3,7 @@
package a
//+JDK
fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit = for (element in this) operation(element)
fun <T> Array<T>.forEach(operation: (T) -> Unit) : Unit { for (element in this) operation(element) }
fun bar(operation: (String) -> Unit) = operation("")
@@ -9,7 +9,7 @@ class event<T>()
fun plusAssign(f : (T) -> Unit) = callbacks.add(f)
fun minusAssign(f : (T) -> Unit) = callbacks.remove(f)
fun call(value : T) = for(c in callbacks) c(value)
fun call(value : T) { for(c in callbacks) c(value) }
}
class MouseMovedEventArgs()
@@ -4,7 +4,7 @@
import java.util.*
fun <T> Iterator<T>.foreach(operation: (element: T) -> Unit) : Unit = while(hasNext()) operation(next())
fun <T> Iterator<T>.foreach(operation: (element: T) -> Unit) : Unit { while(hasNext()) operation(next()) }
fun <T> Iterator<T>.foreach(operation: (index: Int, element: T) -> Unit) : Unit {
var k = 0
@@ -1557,6 +1557,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/controlStructures/ForWithoutBraces.kt");
}
@TestMetadata("ForbidStatementAsDirectFunctionBody.kt")
public void testForbidStatementAsDirectFunctionBody() throws Exception {
doTest("compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.kt");
}
@TestMetadata("kt1075.kt")
public void testKt1075() throws Exception {
doTest("compiler/testData/diagnostics/tests/controlStructures/kt1075.kt");
+1 -1
View File
@@ -253,7 +253,7 @@ public inline fun String.reverse(): String = StringBuilder(this).reverse().toStr
*
* @includeFunctionBody ../../test/StringTest.kt forEach
*/
public inline fun String.forEach(operation: (Char) -> Unit): Unit = for(c in this) operation(c)
public inline fun String.forEach(operation: (Char) -> Unit) { for(c in this) operation(c) }
/**
* Returns *true* if all characters match the given *predicate*