Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong IR or JVM bytecode generation with empty try #174

Open
DaniilStepanov opened this issue Sep 7, 2023 · 2 comments
Open

Wrong IR or JVM bytecode generation with empty try #174

DaniilStepanov opened this issue Sep 7, 2023 · 2 comments
Labels
bug Something isn't working ir

Comments

@DaniilStepanov
Copy link
Collaborator

Example:

    var lambda: (() -> String)? = null

    fun f() {
        try {
        } finally {
            lambda = { "OK" }
        }
    }
    @JvmStatic
    fun box(): String {
        f()
        return lambda?.let { it() } ?: "fail"
    }
@DaniilStepanov
Copy link
Collaborator Author

One more test for try/catch/finally:

fun test1() : String {
    var s = "";
    try {
        try {
            s += "Try";
            throw Exception()
        } catch (x : Exception) {
            s += "Catch";
            throw x
        } finally {
            s += "Finally";
        }
    } catch (x : Exception) {
        return s
    }
}

fun test2() : String {
    var s = "";

    try {
        s += "Try";
        throw Exception()
    } catch (x : Exception) {
        s += "Catch";
    } finally {
        s += "Finally";
    }

    return s
}



fun box() : String {
    if (test1() != "TryCatchFinally") return "fail1: ${test1()}"

    if (test2() != "TryCatchFinally") return "fail2: ${test2()}"

    return "OK"
}

@DaniilStepanov
Copy link
Collaborator Author

More:

fun unsupportedEx() {
    if (true) throw UnsupportedOperationException()
}

fun runtimeEx() {
    if (true) throw RuntimeException()
}

fun test1WithFinally() : String {
    var s = "";
    try {
        try {
            s += "Try";
            unsupportedEx()
        } finally {
            s += "Finally"
        }
    } catch (x : RuntimeException) {
        return s
    }
    return s + "Failed"
}


fun test2WithFinally() : String {
    var s = "";
    try {
        try {
            s += "Try";
            unsupportedEx()
            return s
        } finally {
            s += "Finally"
        }
    } catch (x : RuntimeException) {
        return s
    }
}

fun box() : String {
    if (test1WithFinally() != "TryFinally") return "fail2: ${test1WithFinally()}"

    if (test2WithFinally() != "TryFinally") return "fail4: ${test2WithFinally()}"
    return "OK"
}

@lehvolk lehvolk added the bug Something isn't working label Sep 15, 2023
@lehvolk lehvolk added the ir label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ir
Projects
None yet
Development

No branches or pull requests

2 participants