diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index c118b731633..c1981d7b74c 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -1291,7 +1291,6 @@ public open class Throwable { public final fun (): kotlin.Throwable? public final val message: kotlin.String? public final fun (): kotlin.String? - public final fun printStackTrace(): kotlin.Unit } public object Unit { diff --git a/compiler/testData/cli/jvm/wrongAbiVersion.out b/compiler/testData/cli/jvm/wrongAbiVersion.out index e0c3fdf6be5..0445963d6be 100644 --- a/compiler/testData/cli/jvm/wrongAbiVersion.out +++ b/compiler/testData/cli/jvm/wrongAbiVersion.out @@ -3,6 +3,7 @@ compiler/testData/cli/jvm/wrongAbiVersion.kt:4:5: error: unresolved reference: b bar() ^ compiler/testData/cli/jvm/wrongAbiVersion.kt:6:7: error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch: +public fun kotlin.Throwable.printStackTrace(): kotlin.Unit defined in kotlin public fun kotlin.Throwable.printStackTrace(stream: java.io.PrintStream): kotlin.Unit defined in kotlin public fun kotlin.Throwable.printStackTrace(writer: java.io.PrintWriter): kotlin.Unit defined in kotlin (note: this may be caused by the fact that some classes compiled with an incompatible version of Kotlin were found in the classpath. Such classes cannot be loaded properly by this version of Kotlin compiler. See below for more information) diff --git a/compiler/testData/codegen/box/objects/kt1136.kt b/compiler/testData/codegen/box/objects/kt1136.kt index 9b15a2b1133..2cbe2226747 100644 --- a/compiler/testData/codegen/box/objects/kt1136.kt +++ b/compiler/testData/codegen/box/objects/kt1136.kt @@ -41,10 +41,10 @@ public class SomeClass() { } } -public fun box():String { +public fun box(): String { var obj = SomeClass() - return if(obj.status == null) "OK" else { - obj.status?.printStackTrace() + return if (obj.status == null) "OK" else { + (obj.status as java.lang.Throwable).printStackTrace() "failed" } } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt index cacf8578cc8..9f47baf99c4 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.txt @@ -4,14 +4,12 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public/*package*/ open class JavaClass { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt index 7d967e65165..18b5968f138 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.txt @@ -4,14 +4,12 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public/*package*/ open class JavaClass { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt index 652189b1407..ce72361ebee 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.txt @@ -6,7 +6,6 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public/*package*/ open class JavaClass { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt index c32ab47be3f..abd2f085409 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.txt @@ -4,14 +4,12 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class Impl : test.Trait { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt index 9f4f2382ea8..e432b2bc225 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.txt @@ -13,7 +13,6 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public/*package*/ open class JavaClass { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt index 833fc2bdbd8..ef46713b647 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.txt @@ -8,14 +8,12 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public/*package*/ open class JavaClass { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt index 77e9705472a..370bc73dea0 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.txt @@ -4,14 +4,12 @@ public final class E1 : java.lang.Exception { public constructor E1() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public final class E2 : java.lang.Exception { public constructor E2() public final /*fake_override*/ val cause: kotlin.Throwable? public final /*fake_override*/ val message: kotlin.String? - public final /*fake_override*/ fun printStackTrace(): kotlin.Unit } public/*package*/ open class JavaClass { diff --git a/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.txt b/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.txt index 64af50fe226..5e3b067858b 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.txt +++ b/compiler/testData/diagnostics/tests/controlStructures/catchGenerics.txt @@ -10,7 +10,6 @@ public final class XException : kotlin.Throwable { public final val p: T 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 final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } @@ -21,7 +20,6 @@ public final class YException : java.lang.RuntimeException { public final val p: T 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 final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } @@ -32,6 +30,5 @@ public final class ZException : java.lang.Exception { public final val p: T 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 final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } diff --git a/compiler/testData/diagnostics/tests/regressions/kt498.txt b/compiler/testData/diagnostics/tests/regressions/kt498.txt index 3d6317f308d..f4cb87a3793 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt498.txt +++ b/compiler/testData/diagnostics/tests/regressions/kt498.txt @@ -8,6 +8,5 @@ public final class IdUnavailableException : java.lang.Exception { public final override /*1*/ /*fake_override*/ val message: kotlin.String? 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 final override /*1*/ /*fake_override*/ fun printStackTrace(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } diff --git a/core/builtins/native/kotlin/Throwable.kt b/core/builtins/native/kotlin/Throwable.kt index 77eab929f36..7a38d638692 100644 --- a/core/builtins/native/kotlin/Throwable.kt +++ b/core/builtins/native/kotlin/Throwable.kt @@ -23,14 +23,9 @@ package kotlin * @param cause the cause of this throwable. */ public open class Throwable(val message: String?, val cause: Throwable?) { - constructor(message: String?) : this(message, null) constructor(cause: Throwable?) : this(cause?.toString(), cause) constructor() : this(null, null) - /** - * Prints the stack trace of this throwable to the standard output. - */ - public fun printStackTrace(): Unit } diff --git a/libraries/stdlib/src/kotlin/util/StandardJVM.kt b/libraries/stdlib/src/kotlin/util/StandardJVM.kt index 63c46b4dc50..26193b510cd 100644 --- a/libraries/stdlib/src/kotlin/util/StandardJVM.kt +++ b/libraries/stdlib/src/kotlin/util/StandardJVM.kt @@ -7,7 +7,15 @@ import java.io.PrintStream import java.io.PrintWriter /** - * Allows a stack trace to be printed from Kotlin's [Throwable]. + * Prints the stack trace of this throwable to the standard output. + */ +public fun Throwable.printStackTrace(): Unit { + val jlt = this as java.lang.Throwable + jlt.printStackTrace() +} + +/** + * Prints the stack trace of this throwable to the specified [writer]. */ public fun Throwable.printStackTrace(writer: PrintWriter): Unit { val jlt = this as java.lang.Throwable @@ -15,7 +23,7 @@ public fun Throwable.printStackTrace(writer: PrintWriter): Unit { } /** - * Allows a stack trace to be printed from Kotlin's [Throwable]. + * Prints the stack trace of this throwable to the specified [stream]. */ public fun Throwable.printStackTrace(stream: PrintStream): Unit { val jlt = this as java.lang.Throwable