Added tests on labels

#KT-1703 Fixed
 #KT-361 Fixed
 #KT-3920 Fixed
 #KT-3988 Fixed
 #KT-4247 Fixed
 #KT-4586 Fixed
 #KT-4603 Fixed
 #KT-591 Fixed
This commit is contained in:
Svetlana Isakova
2014-05-14 13:57:14 +04:00
parent a02af7344e
commit 69e5444ddf
10 changed files with 190 additions and 1 deletions
@@ -0,0 +1,15 @@
//KT-1703 Reference to label is unresolved
fun test() {
val ints = Array<Int?>(2, { null })
ints.forEach @lit {
if (it == null) <!RETURN_NOT_ALLOWED_EXPLICIT_RETURN_TYPE_REQUIRED!>return @lit<!>
use(<!DEBUG_INFO_AUTOCAST!>it<!> + 5)
}
}
fun <T> Array<out T>.forEach(operation: (T) -> Unit) {
for (element in this) operation(element)
}
fun use(a: Any?) = a
@@ -0,0 +1,12 @@
fun nonlocals(b : Boolean) {
@a{(): Int ->
fun foo() {
if (b) {
<!RETURN_NOT_ALLOWED!>return@a 1<!> // The label must be resolved, but an error should be reported for a non-local return
}
}
return@a 5
}
}
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
//KT-3920 Labeling information is lost when passing through some expressions
fun test() {
run @f{ (): Int ->
val x = if (1 > 2) return@f 1 else 2
2
}
}
fun <T> run(f: () -> T): T = f()
@@ -0,0 +1,21 @@
//KT-3988 This@label for outer function not resolved
class Comment() {
var article = ""
}
class Comment2() {
var article2 = ""
}
fun new(body: Comment.() -> Unit) = body
fun new2(body: Comment2.() -> Unit) = body
fun main(args: Array<String>) {
new {
new2 {
this@new //UNRESOLVED REFERENCE
}
}
}
@@ -0,0 +1,11 @@
//KT-4247 LABEL_NAME_CLASH
fun foo(bar1: (String.() -> Int) -> Int) {
bar1 {
this.length
}
bar1 {
this@bar1.length
}
}
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
//KT-4586 this@ does not work for builders
fun string(init: StringBuilder.() -> Unit): String{
val answer = StringBuilder()
answer.init()
return answer.toString()
}
val str = string @l{
append("hello, ")
val sub = string {
append("world!")
this@l.append(this)
}
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
//KT-4603 Labeling information is lost when passing through local classes or objects
fun foo() {
val s = @l{ Int.() ->
class Local(val y: Int = this@l) {
fun bar() {
val x: Int = this@l //unresolved
}
}
}
}
@@ -0,0 +1,11 @@
//KT-591 Unresolved label in valid code
fun test() {
val <!UNUSED_VARIABLE!>a<!> = @a{(Int?).() ->
if (this != null) {
val <!UNUSED_VARIABLE!>b<!> = {String.() ->
<!DEBUG_INFO_AUTOCAST!>this@a<!>.times(5) // @a Unresolved
}
}
}
}
@@ -0,0 +1,25 @@
trait A {
fun foo()
}
trait B {
fun bar()
}
fun B.b() {
object : A {
override fun foo() {
this@b.bar()
}
}
}
fun test() {
@b { B.() ->
object : A {
override fun foo() {
this@b.bar()
}
}
}
}
@@ -33,7 +33,7 @@ import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTest;
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class, JetDiagnosticsTestGenerated.TailRecursion.class})
public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
@TestMetadata("compiler/testData/diagnostics/tests")
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ClassObjects.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.CyclicHierarchy.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.DelegatedProperty.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Evaluate.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.Imports.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inline.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.Multimodule.class, Tests.NamedArguments.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Numbers.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Suppress.class, Tests.ThisAndSuper.class, Tests.Typedefs.class, Tests.Unit.class, Tests.Varargs.class, Tests.When.class})
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ClassObjects.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.CyclicHierarchy.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.DelegatedProperty.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Evaluate.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.Imports.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inline.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Labels.class, Tests.Library.class, Tests.Multimodule.class, Tests.NamedArguments.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Numbers.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Suppress.class, Tests.ThisAndSuper.class, Tests.Typedefs.class, Tests.Unit.class, Tests.Varargs.class, Tests.When.class})
public static class Tests extends AbstractJetDiagnosticsTest {
@TestMetadata("Abstract.kt")
public void testAbstract() throws Exception {
@@ -4605,6 +4605,59 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
}
}
@TestMetadata("compiler/testData/diagnostics/tests/labels")
public static class Labels extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInLabels() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/tests/labels"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("kt1703.kt")
public void testKt1703() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt1703.kt");
}
@TestMetadata("kt361.kt")
public void testKt361() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt361.kt");
}
@TestMetadata("kt3920.kt")
public void testKt3920() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt3920.kt");
}
@TestMetadata("kt3988.kt")
public void testKt3988() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt3988.kt");
}
@TestMetadata("kt4247.kt")
public void testKt4247() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt4247.kt");
}
@TestMetadata("kt4586.kt")
public void testKt4586() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt4586.kt");
}
@TestMetadata("kt4603.kt")
public void testKt4603() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt4603.kt");
}
@TestMetadata("kt591.kt")
public void testKt591() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/kt591.kt");
}
@TestMetadata("labelReferencesInsideObjectExpressions.kt")
public void testLabelReferencesInsideObjectExpressions() throws Exception {
doTest("compiler/testData/diagnostics/tests/labels/labelReferencesInsideObjectExpressions.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/library")
public static class Library extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInLibrary() throws Exception {
@@ -7029,6 +7082,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
suite.addTest(Inner.innerSuite());
suite.addTestSuite(J_k.class);
suite.addTest(Jdk_annotations.innerSuite());
suite.addTestSuite(Labels.class);
suite.addTestSuite(Library.class);
suite.addTestSuite(Multimodule.class);
suite.addTestSuite(NamedArguments.class);