flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.09k stars 150 forks source link

Imported Java types cannot be used in `catch` blocks #4989

Open paulbutcher opened 1 year ago

paulbutcher commented 1 year ago

So this compiles successfully:

import java.lang.{NullPointerException, Object};

def main(): Unit \ IO = try {
    import java.lang.Object.toString(): String \ {};
    println(toString(null as Object))
} catch {
    case _: ##java.lang.NullPointerException => println("Exception happened")
}

But this does not:

import java.lang.{NullPointerException, Object};

def main(): Unit \ IO = try {
    import java.lang.Object.toString(): String \ {};
    println(toString(null as Object))
} catch {
    case _: NullPointerException => println("Exception happened")
}

Giving the error:

❌ -- Parse Error -------------------------------------------------- file:///Users/paulbutcher/Projects/Flix/flix-playground/src/Main.flix

>> Parse Error: Invalid input 'N', expected "##" (line 7, column 13):
    case _: NullPointerException => println("Exception happened")
            ^
magnus-madsen commented 1 year ago

I think this should be a simple fix, but probably worth waiting for Matts big restructuring.

magnus-madsen commented 1 year ago

(As a side comment: I believe that try-catch are somewhat broken in Flix due to the difficulty of code generation. (At least nested try-catch).

JonathanStarup commented 1 year ago

only nested trys inside the same function afaik