Skip to content

New error handling - #26956

Open
odersky wants to merge 4 commits into
scala:mainfrom
dotty-staging:new-error-handlung
Open

odersky wants to merge 4 commits into
scala:mainfrom
dotty-staging:new-error-handlung

Conversation

@odersky

@odersky odersky commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

New language feature: experimental.errorHandling. It needs -Yexplicit-nulls to be also set

This enables the following:

  • Add maybe types T? and T ? E.
  • Add maybe prompt and postfix e? operator
  • Implement subtype rules
  • Implement erasure rules
  • Special pattern-matching rules for Ok and Err extractors

Have you relied on LLM-based tools in this contribution?

I have relied on LLMs to

  • make proposals how to adapt the logic in Space.scala to the new types
  • generate some of the tests from the tests we had for Option
  • give some hints for debugging.

@odersky
odersky force-pushed the new-error-handlung branch 4 times, most recently from b3f43df to 5bf722b Compare August 31, 2026 21:01
New language feature: experimental.errorHandling. It needs -Yexplicit-nulls to be also set

This enables the following:

 - Add maybe types T? and T ? E.
 - Add amybe prompt and postfix e? operator
 - Implement subtype rules
 - Implement erasure rules
 - Special pattern-matching rules for Ok and Err extractors
@noti0na1

noti0na1 commented Sep 2, 2026

Copy link
Copy Markdown
Member

While doing a quick test with this PR locally, I find some issues with type erasure and type bounds, worth adding some tests:

// type erasure and generic signature would give different results, so calling f in Java may have issue
def f(x: String?): String? = x
def f1(x: String?): String = x match
  case Ok(y) => y
  case null => "none"

def f2[T <: String](x: T?): String = x match
  case Ok(y) => y
  case null => "none"

def f3[T <: String?](x: T): String = x match
  case Ok(y) => y
  case null => "none"

val s: String? = "a"
val b = s.isEmpty

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.

2 participants