Merge remote branch 'origin/master'
Conflicts: compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java
This commit is contained in:
@@ -36,15 +36,3 @@ l1:
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
== a ==
|
||||
val a = Array<Int>
|
||||
---------------------
|
||||
l0:
|
||||
<START>
|
||||
r(Array)
|
||||
r(Array<Int>)
|
||||
l1:
|
||||
<END>
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
|
||||
@@ -55,56 +55,3 @@ l1:
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
== x ==
|
||||
var x = 1
|
||||
---------------------
|
||||
l0:
|
||||
<START>
|
||||
r(1)
|
||||
l1:
|
||||
<END>
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
== y ==
|
||||
val y = true && false
|
||||
---------------------
|
||||
l0:
|
||||
<START>
|
||||
r(true)
|
||||
jf(l2)
|
||||
r(false)
|
||||
l2:
|
||||
r(true && false)
|
||||
l1:
|
||||
<END>
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
== z ==
|
||||
val z = false && true
|
||||
---------------------
|
||||
l0:
|
||||
<START>
|
||||
r(false)
|
||||
jf(l2)
|
||||
r(true)
|
||||
l2:
|
||||
r(false && true)
|
||||
l1:
|
||||
<END>
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
== t ==
|
||||
val t = Test()
|
||||
---------------------
|
||||
l0:
|
||||
<START>
|
||||
r(Test)
|
||||
r(Test())
|
||||
l1:
|
||||
<END>
|
||||
error:
|
||||
<ERROR>
|
||||
=====================
|
||||
|
||||
@@ -136,9 +136,9 @@ fun tf() : Int {
|
||||
}
|
||||
|
||||
fun failtest(a : Int) : Int {
|
||||
<error>if (fail() || true) {
|
||||
if (fail() || <error>true</error>) {
|
||||
|
||||
}</error>
|
||||
}
|
||||
<error>return 1</error>
|
||||
}
|
||||
|
||||
|
||||
@@ -25,4 +25,61 @@ class C {
|
||||
<!NOT_A_LOOP_LABEL!>break@f<!>
|
||||
}
|
||||
|
||||
fun containsBreak(a: String?, b: String?) {
|
||||
while (a == null) {
|
||||
break;
|
||||
}
|
||||
a?.compareTo("2")
|
||||
}
|
||||
|
||||
fun notContainsBreak(a: String?, b: String?) {
|
||||
while (a == null) {
|
||||
while (b == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
a<!UNNECESSARY_SAFE_CALL!>?.<!>compareTo("2")
|
||||
}
|
||||
|
||||
fun containsBreakWithLabel(a: String?) {
|
||||
@loop while(a == null) {
|
||||
break@loop
|
||||
}
|
||||
a?.compareTo("2")
|
||||
}
|
||||
|
||||
fun containsIllegalBreak(a: String?) {
|
||||
@loop while(a == null) {
|
||||
<!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@label<!><!>
|
||||
}
|
||||
a<!UNNECESSARY_SAFE_CALL!>?.<!>compareTo("2")
|
||||
}
|
||||
|
||||
fun containsBreakToOuterLoop(a: String?, b: String?) {
|
||||
@loop while(b == null) {
|
||||
while(a == null) {
|
||||
break@loop
|
||||
}
|
||||
a<!UNNECESSARY_SAFE_CALL!>?.<!>compareTo("2")
|
||||
}
|
||||
}
|
||||
|
||||
fun containsBreakInsideLoopWithLabel(a: String?, array: Array<Int>) {
|
||||
@ while(a == null) {
|
||||
for (el in array) {
|
||||
break@
|
||||
}
|
||||
}
|
||||
a?.compareTo("2")
|
||||
}
|
||||
|
||||
fun unresolvedBreak(a: String?, array: Array<Int>) {
|
||||
while(a == null) {
|
||||
@ for (el in array) {
|
||||
break
|
||||
}
|
||||
if (true) break else <!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@<!><!>
|
||||
}
|
||||
a?.compareTo("2")
|
||||
}
|
||||
}
|
||||
@@ -168,4 +168,42 @@ fun f(): Int = if (1 < 2) 1 else returnNothing()
|
||||
public fun <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>f<!>() = 1
|
||||
class B() {
|
||||
protected fun <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>f<!>() = "ss"
|
||||
}
|
||||
|
||||
fun testFunctionLiterals() {
|
||||
val endsWithVarDeclaration : fun() : Boolean = {
|
||||
<!EXPECTED_TYPE_MISMATCH!>val x = 2<!>
|
||||
}
|
||||
|
||||
val endsWithAssignment = { () : Int =>
|
||||
val x = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x = 333<!>
|
||||
}
|
||||
|
||||
val endsWithReAssignment = { () : Int =>
|
||||
val x = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x += 333<!>
|
||||
}
|
||||
|
||||
val endsWithFunDeclaration : fun() : String = {
|
||||
val x = 1
|
||||
x = 333
|
||||
<!EXPECTED_TYPE_MISMATCH!>fun meow() : Unit {}<!>
|
||||
}
|
||||
|
||||
val endsWithObjectDeclaration : fun() : Int = {
|
||||
val x = 1
|
||||
x = 333
|
||||
<!EXPECTED_TYPE_MISMATCH!>object A {}<!>
|
||||
}
|
||||
|
||||
val expectedUnitReturnType1 = { () : Unit =>
|
||||
val x = 1
|
||||
}
|
||||
|
||||
val expectedUnitReturnType2 = { () : Unit =>
|
||||
fun meow() : Unit {}
|
||||
object A {}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace return
|
||||
|
||||
class A {
|
||||
fun outer() {
|
||||
fun inner() {
|
||||
if (1 < 2)
|
||||
return@inner
|
||||
else
|
||||
return@outer
|
||||
}
|
||||
if (1 < 2)
|
||||
<!NOT_A_RETURN_LABEL!>return@A<!>
|
||||
else if (2 < 3)
|
||||
<!NOT_A_RETURN_LABEL!>return<!UNRESOLVED_REFERENCE!>@inner<!><!>
|
||||
return@outer
|
||||
}
|
||||
}
|
||||
@@ -136,16 +136,16 @@ fun tf() : Int {
|
||||
}
|
||||
|
||||
fun failtest(a : Int) : Int {
|
||||
<!UNREACHABLE_BECAUSE_OF_NOTHING!>if (fail() || true) {
|
||||
if (fail() || <!UNREACHABLE_CODE!>true<!>) {
|
||||
|
||||
}<!>
|
||||
<!UNREACHABLE_BECAUSE_OF_NOTHING!>return 1<!>
|
||||
}
|
||||
<!UNREACHABLE_CODE!>return 1<!>
|
||||
}
|
||||
|
||||
fun foo(a : Nothing) : Unit {
|
||||
1
|
||||
a
|
||||
<!UNREACHABLE_BECAUSE_OF_NOTHING!>2<!>
|
||||
<!UNREACHABLE_CODE!>2<!>
|
||||
}
|
||||
|
||||
fun fail() : Nothing {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun launch(f : fun() : Unit) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val list = ArrayList<Int>()
|
||||
val foo : fun() : Unit = {
|
||||
list.add(2) //first exception
|
||||
}
|
||||
foo()
|
||||
|
||||
launch({
|
||||
list.add(3)
|
||||
})
|
||||
|
||||
val bar = {
|
||||
val x = 1 //second exception
|
||||
}
|
||||
bar()
|
||||
|
||||
return if (list.size() == 2 && list.get(0) == 2 && list.get(1) == 3) "OK" else "fail"
|
||||
}
|
||||
@@ -58,4 +58,46 @@ public class ArrayGenTest extends CodegenTestCase {
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof Integer);
|
||||
}
|
||||
|
||||
public void testIterator () throws Exception {
|
||||
loadText("fun box() { val x = Array<Int>(5, { it } ).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testPrimitiveIterator () throws Exception {
|
||||
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testLongIterator () throws Exception {
|
||||
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testCharIterator () throws Exception {
|
||||
loadText("fun box() { val x = CharArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testArrayIndices () throws Exception {
|
||||
loadText("fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
|
||||
public void testCharIndices () throws Exception {
|
||||
loadText("fun box() { val x = CharArray(5).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
foo.invoke(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,4 +178,16 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
blackBoxFile("regressions/kt48.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testKt309 () throws Exception {
|
||||
loadText("fun box() = null");
|
||||
final Method method = generateFunction("box");
|
||||
assertEquals(method.getReturnType().getName(), "java.lang.Object");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testKt343 () throws Exception {
|
||||
blackBoxFile("regressions/kt343.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package org.jetbrains.jet.codegen;
|
||||
public class ClosuresGenTest extends CodegenTestCase {
|
||||
public void testSimplestClosure() throws Exception {
|
||||
blackBoxFile("classes/simplestClosure.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testSimplestClosureAndBoxing() throws Exception {
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.IntRange;
|
||||
import jet.Tuple2;
|
||||
import jet.Tuple3;
|
||||
import jet.Tuple4;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
@@ -9,6 +11,7 @@ import java.awt.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -489,12 +492,23 @@ public class NamespaceGenTest extends CodegenTestCase {
|
||||
|
||||
public void testTupleLiteral() throws Exception {
|
||||
loadText("fun foo() = (1, \"foo\")");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
Tuple2 tuple2 = (Tuple2) main.invoke(null);
|
||||
assertEquals(1, tuple2._1);
|
||||
assertEquals("foo", tuple2._2);
|
||||
}
|
||||
|
||||
public void testParametrizedTupleLiteral() throws Exception {
|
||||
loadText("fun <E,D> E.foo(extra: java.util.List<D>) = (1, \"foo\", this, extra)");
|
||||
System.out.println(generateToText());
|
||||
final Method main = generateFunction();
|
||||
Tuple4 tuple4 = (Tuple4) main.invoke(null, "aaa", Arrays.asList(10), TypeInfo.STRING_TYPE_INFO, TypeInfo.INT_TYPE_INFO);
|
||||
assertEquals(1, tuple4._1);
|
||||
assertEquals("foo", tuple4._2);
|
||||
assertEquals("aaa", tuple4._3);
|
||||
}
|
||||
|
||||
public void testPredicateOperator() throws Exception {
|
||||
loadText("fun foo(s: String) = s?startsWith(\"J\")");
|
||||
final Method main = generateFunction();
|
||||
|
||||
@@ -90,13 +90,13 @@ public class PatternMatchingTest extends CodegenTestCase {
|
||||
Method foo = generateFunction();
|
||||
final Object result;
|
||||
try {
|
||||
result = foo.invoke(null, new Tuple2<Integer, Integer>(1, 2));
|
||||
result = foo.invoke(null, new Tuple2<Integer, Integer>(null, 1, 2));
|
||||
} catch (Exception e) {
|
||||
System.out.println(generateToText());
|
||||
throw e;
|
||||
}
|
||||
assertEquals("one,two", result);
|
||||
assertEquals("something", foo.invoke(null, new Tuple2<String, String>("not", "tuple")));
|
||||
assertEquals("something", foo.invoke(null, new Tuple2<String, String>(null, "not", "tuple")));
|
||||
}
|
||||
|
||||
public void testCall() throws Exception {
|
||||
@@ -119,8 +119,8 @@ public class PatternMatchingTest extends CodegenTestCase {
|
||||
public void testNames() throws Exception {
|
||||
loadText("fun foo(x: (Any, Any)) = when(x) { is (val a is String, *) => a; else => \"something\" }");
|
||||
Method foo = generateFunction();
|
||||
assertEquals("JetBrains", foo.invoke(null, new Tuple2<String, String>("JetBrains", "s.r.o.")));
|
||||
assertEquals("something", foo.invoke(null, new Tuple2<Integer, Integer>(1, 2)));
|
||||
assertEquals("JetBrains", foo.invoke(null, new Tuple2<String, String>(null, "JetBrains", "s.r.o.")));
|
||||
assertEquals("something", foo.invoke(null, new Tuple2<Integer, Integer>(null, 1, 2)));
|
||||
}
|
||||
|
||||
public void testMultipleConditions() throws Exception {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
@NotNull
|
||||
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, List<TypeProjection> typeArguments, String name, JetType... parameterType) {
|
||||
List<JetType> parameterTypeList = Arrays.asList(parameterType);
|
||||
JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext(), JetFlowInformationProvider.NONE);
|
||||
JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> functions = typeInferrerServices.getCallResolver().resolveExactSignature(
|
||||
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
|
||||
|
||||
@@ -493,14 +493,14 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
private void assertType(String expression, JetType expectedType) {
|
||||
Project project = getProject();
|
||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE, JetFlowInformationProvider.NONE).getType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).getType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||
assertTrue(type + " != " + expectedType, type.equals(expectedType));
|
||||
}
|
||||
|
||||
private void assertErrorType(String expression) {
|
||||
Project project = getProject();
|
||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE, JetFlowInformationProvider.NONE).safeGetType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).safeGetType(scopeWithImports, jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
|
||||
Project project = getProject();
|
||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE, JetFlowInformationProvider.NONE).getType(addImports(scope), jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||
JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).getType(addImports(scope), jetExpression, JetTypeInferrer.NO_EXPECTED_TYPE);
|
||||
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
|
||||
assertEquals(expectedType, type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user