Skip to content

Conversation

@eejbyfeldt
Copy link
Contributor

@eejbyfeldt eejbyfeldt commented Dec 13, 2025

fixes: #24357

@eejbyfeldt
Copy link
Contributor Author

@hamzaremmal Maybe you could review since you left a comment on the issue. Reading the doc for TryCatchPatterns i am still convinced that this is the expected behavior.

@eejbyfeldt eejbyfeldt marked this pull request as ready for review December 13, 2025 12:12
@hamzaremmal
Copy link
Member

Hi @eejbyfeldt, the diff seems small but I want to double check things for a spec point of view before approving. I'll add it into my todos of next week.

@hamzaremmal hamzaremmal self-assigned this Dec 13, 2025
@hamzaremmal hamzaremmal self-requested a review December 13, 2025 12:19
@noti0na1
Copy link
Member

noti0na1 commented Dec 13, 2025

I think this PR has the correct behaviour, given we consider the catch part as pattern matching in spec.

I'm wondering, can we generate byte code for simple catch like case _: E1 | E2 | E3 | ... directly as well, rather than generating another pattern match, as Java supports multi-catch?

@som-snytt
Copy link
Contributor

I remember that try-catch doesn't support TypeTest but does support ClassTag. (I remember replying to someone's question on the forum.)

I have a local test about saferExceptions where a transparent inline method expands to try-catch but I didn't get it to work; my point is that try-catch isn't as simple as "if I can do it with a plain pattern match, it works in catch".

@noti0na1
Copy link
Member

I have a local test about saferExceptions where a transparent inline method expands to try-catch but I didn't get it to work

I'm curious, can I take a look of the test?

@som-snytt
Copy link
Contributor

@noti0na1 Sorry I have no idea why I wrote this. Probably just noodling.

import language.experimental.saferExceptions
import java.io.IOException
import scala.reflect.ClassTag

def io(): Unit throws IOException = throw IOException()

def ok =
  try io()
  catch case ioe: IOException => println("drat")

transparent inline def nok[E <: Exception : {CanThrow, ClassTag}](inline body: CanThrow[E] ?=> Unit) =
  try body
  catch case e: E => println("darn")

def test =
  nok[IOException]:
    io()

@som-snytt som-snytt changed the title Delias in isSimpleThrowable check Dealias in isSimpleThrowable check Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Catch case with alias of union type catches types not in union

4 participants