From eeeb741d42b15576f4011a779ae87179c764b191 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 7 Apr 2015 21:10:42 +0300 Subject: [PATCH] Added test for obsolete bug and removed workaround in code. --- .../diagnostics/tests/overload/kt2493.kt | 19 ++++++++++ .../diagnostics/tests/overload/kt2493.txt | 38 +++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 6 +++ .../main/kotlin/kotlin/jdbc/Connections.kt | 2 +- .../main/kotlin/kotlin/jdbc/DataSources.kt | 12 +++--- .../src/main/kotlin/kotlin/jdbc/Statements.kt | 2 +- 6 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/overload/kt2493.kt create mode 100644 compiler/testData/diagnostics/tests/overload/kt2493.txt diff --git a/compiler/testData/diagnostics/tests/overload/kt2493.kt b/compiler/testData/diagnostics/tests/overload/kt2493.kt new file mode 100644 index 00000000000..2d8bcf47b24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt2493.kt @@ -0,0 +1,19 @@ +trait A +trait B + +fun R.f() { +} + +fun R.f() { +} + +class AImpl: A +class BImpl: B + +class C: A, B + +fun main(args: Array) { + AImpl().f() + BImpl().f() + C().f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/overload/kt2493.txt b/compiler/testData/diagnostics/tests/overload/kt2493.txt new file mode 100644 index 00000000000..35eb7886c1c --- /dev/null +++ b/compiler/testData/diagnostics/tests/overload/kt2493.txt @@ -0,0 +1,38 @@ +package + +internal fun main(/*0*/ args: kotlin.Array): kotlin.Unit +internal fun R.f(): kotlin.Unit +internal fun R.f(): kotlin.Unit + +internal trait A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class AImpl : A { + public constructor AImpl() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal trait B { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class BImpl : B { + public constructor BImpl() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class C : A, B { + public constructor C() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index b8e717880d9..d72e5568fb0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -8437,6 +8437,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt2493.kt") + public void testKt2493() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/kt2493.kt"); + doTest(fileName); + } + @TestMetadata("kt7068.kt") public void testKt7068() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/kt7068.kt"); diff --git a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt index 7dae5d30f20..5e784ee0cee 100644 --- a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt +++ b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt @@ -37,7 +37,7 @@ fun Connection.use(block : (Connection) -> T) : T { fun Connection.statement(block: (Statement) -> T): T { val statement = createStatement() if (statement != null) { - return statement.useSql(block) + return statement.use(block) } else { throw IllegalStateException("No Statement returned from $this") } diff --git a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/DataSources.kt b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/DataSources.kt index b0693e1966c..5b3c9c8b41f 100644 --- a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/DataSources.kt +++ b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/DataSources.kt @@ -7,7 +7,7 @@ import kotlin.template.StringTemplate /** * Processes a connection from the pool using the given function block */ -fun DataSource.useDataSource(block : (Connection) -> T): T { // TODO rename to "use" when KT-2493 is fixed +fun DataSource.use(block : (Connection) -> T): T { val connection = getConnection() if (connection != null) { try { @@ -24,33 +24,33 @@ fun DataSource.useDataSource(block : (Connection) -> T): T { // TODO rename * Helper method to process a statement on this collection */ fun DataSource.statement(block: (Statement) -> T): T { - return useDataSource{ it.statement(block) } + return use { it.statement(block) } } /** * Perform an SQL update on the connection */ fun DataSource.update(sql: String): Int { - return useDataSource{ it.update(sql) } + return use { it.update(sql) } } /** * Perform a query on the connection and processes the result set with a function */ fun DataSource.query(sql: String, block: (ResultSet) -> T): T { - return useDataSource{ it.query(sql, block) } + return use { it.query(sql, block) } } /** * Performs the update using the given SQL using a [[StringTemplate]] */ fun DataSource.update(template : StringTemplate) : Int { - return useDataSource{ it.update(template) } + return use { it.update(template) } } /** * Perform a query on the connection using the SQL from the [[StringTemplate]] and processes the result set with a function */ fun DataSource.query(template : StringTemplate, resultBlock : (ResultSet) -> T) : T { - return useDataSource{ it.query(template, resultBlock) } + return use { it.query(template, resultBlock) } } diff --git a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Statements.kt b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Statements.kt index ca2361d6dc2..72030555dab 100644 --- a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Statements.kt +++ b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Statements.kt @@ -8,7 +8,7 @@ import java.sql.Statement /** * Uses the statement with the given block then closes the statement */ -fun S.useSql(block : (S) -> T) : T { // TODO rename to "use" when KT-2493 is fixed +fun S.use(block : (S) -> T) : T { try { return block(this) } finally {