Skip to content

Add maybe types - #26814

Draft
odersky wants to merge 24 commits into
scala:mainfrom
dotty-staging:add-maybe-types
Draft

Add maybe types#26814
odersky wants to merge 24 commits into
scala:mainfrom
dotty-staging:add-maybe-types

Conversation

@odersky

@odersky odersky commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Trial balloon for a new kind of maybe type T?.

@odersky
odersky force-pushed the add-maybe-types branch 2 times, most recently from 917f514 to 2cce1f6 Compare August 17, 2026 21:06
odersky added 14 commits August 19, 2026 18:40
 - Enabled by experimental.magic
 - Independent of language.postfixOps
 - Highest precedence
ExtractDependencies fell into a "NoDenotation cannot be cast to ClassDenotation"
assertioin violation. When recompiling after some changes. This fix avoids that.
Otherwise the maybe logic does not work correctly.

It would be nice if we could link explicit-nulls with magic, but that does not
work since explicit-nulls is a global flag that has to be set when the compiler
starts up. We can't even change it from run to run.
Special cases needed for subtyping, erasure, and pattern matching.
The erasure of Maybe changes after bootstrapped. So anything that
touches it can compile only with the bootstrapped compiler.
Also: Drop $ in front of Maybe, no harm in using it directly, since it is a sealed
trait.

Also: Fix exhaustivity checking for Ok patterns
 - Drop OK unapply call, which is known to be the identity
 - Simplify leading null test for maybe types
Also, move back bootstrapped library and tests to regular. Since we now inline
Ok.unapply, we are no longer affected by difference in erasure between
bootstrapped and non-bootstrapped.
Plus a lot more tests
Needed to avoid erasure difference between bootstrapped and non-bootstrapped compilers.
So for T not nullable, we now have T? =:= T | Null.
We don't need it directly, since source programs use `?` instead.

Also: Fix printing of maybe type trees.
Also: drop overfitted condition by Claude in space engine.
To reduce added linecount we drop a bunch of tests that are straightforward Option -> ?
substitutions.
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.

1 participant