Skip to content

Enhance safe mode - #25638

Merged
noti0na1 merged 3 commits into
scala:mainfrom
dotty-staging:enhance-safe-mode
Mar 31, 2026
Merged

Enhance safe mode#25638
noti0na1 merged 3 commits into
scala:mainfrom
dotty-staging:enhance-safe-mode

Conversation

@noti0na1

@noti0na1 noti0na1 commented Mar 27, 2026

Copy link
Copy Markdown
Member

This PR enhance safe mode and fix a bug:

  • add sym exists check: the test in Fixes to Safe Mode Checking #25603 forgets the safe mode import
  • add some more safe Java classes
  • enforce pattern match exhaustivity: The reason to enforce pattern match exhaustivity is one can intentionally create runtime exceptions by not matching a case.

Close #25389

How much have you relied on LLM-based tools in this contribution?

Ask for suggestions on which classes to add

@bishabosha

Copy link
Copy Markdown
Member

Im a bit surprised that some pattern matches work and others not e.g. #25389

@noti0na1

noti0na1 commented Mar 27, 2026

Copy link
Copy Markdown
Member Author

Technically, the last case of an exhaustive match can be marked as assumed safe.

We cannot just mark OpsPackageClass assumed safe for now. We need to way to specify throw is impure.

@noti0na1
noti0na1 marked this pull request as ready for review March 27, 2026 18:18
@noti0na1
noti0na1 requested a review from odersky March 28, 2026 11:01

@odersky odersky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing the exhaustivity part and leave it to be discussed further.

Comment thread compiler/src/dotty/tools/dotc/transform/patmat/Space.scala Outdated
* fix sym exists check
* add some Java classes
* enforce pattern match exhaustivity
@noti0na1
noti0na1 force-pushed the enhance-safe-mode branch from 5c041ed to 04881b7 Compare March 30, 2026 01:22
@noti0na1

Copy link
Copy Markdown
Member Author

If we think runtime exceptions are fine, then there is not need to forbid throw in safe mode I guess?

@odersky

odersky commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

If we think runtime exceptions are fine, then there is not need to forbid throw in safe mode I guess?

Indeed.

@noti0na1

Copy link
Copy Markdown
Member Author

OK, I will add OpsPackageClass to the list

@noti0na1
noti0na1 requested a review from odersky March 30, 2026 18:13
@noti0na1
noti0na1 merged commit baad2dd into scala:main Mar 31, 2026
64 checks passed
@noti0na1
noti0na1 deleted the enhance-safe-mode branch March 31, 2026 09:44
@WojciechMazur WojciechMazur added this to the 3.8.4 milestone Mar 31, 2026
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.

Impossible to write any pattern match in safe mode, "Cannot refer to method throw"

5 participants