Skip to content

Conversation

@zielinsky
Copy link
Member

@zielinsky zielinsky commented Jan 14, 2026

Fixes #24750
Fixes #21881

@som-snytt
Copy link
Contributor

som-snytt commented Jan 14, 2026

I mentioned on the ticket that they can't be used in annotations. I tried one approach that was too clever, rewriting them as inline transparent def. Just in case there's an easy fix to the type, since enums are not constant (any more).

Edit: I guess the singleton type will be visible in the back end, at least, which is currently widened!

@zielinsky zielinsky marked this pull request as ready for review January 15, 2026 09:39
@zielinsky
Copy link
Member Author

zielinsky commented Jan 15, 2026

I mentioned on the ticket that they can't be used in annotations. I tried one approach that was too clever, rewriting them as inline transparent def. Just in case there's an easy fix to the type, since enums are not constant (any more).

Edit: I guess the singleton type will be visible in the back end, at least, which is currently widened!

@som-snytt now they can! Look at 7fee34d !:> Used exactly your insight - the singleton type is visible in backend. Should I mark this as fixing #21881?

@zielinsky zielinsky requested a review from som-snytt January 15, 2026 13:25
@som-snytt
Copy link
Contributor

som-snytt commented Jan 15, 2026

@zielinsky that's amazing, thanks. I took a look yesterday and didn't formulate it correctly.

Yes, I think this is sufficient for the use case in #21881.

Edit: I just deleted my local branch issue/21881-post-zielinsky.

@zielinsky zielinsky requested review from odersky and removed request for som-snytt January 15, 2026 20:45
else
val isJavaEnumValue = tp match
case tp: TermRef => tp.termSymbol.isAllOf(JavaDefined | Enum)
case _ => false
Copy link
Contributor

Choose a reason for hiding this comment

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

technically, in this form the val is too eager, albeit not expensive. Currently, I like inline def for local helpers. (It would be nice if it were inlined without asking.)

@som-snytt
Copy link
Contributor

som-snytt commented Jan 16, 2026

FSR I get the complement in the warn test.

It would fail on pattern case: NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS

I was about to inspect the back end fix.

Clean build (?) has similar warning in Duration.scala.

Edit: the difference is bootstrapped.

sbt:scala3-bootstrapped> scalac tests/pos/i24750.scala
[info] running (fork) dotty.tools.dotc.Main -d /home/amarki/projects/scala3/out/default-last-scalac-out.jar -classpath /home/amarki/projects/scala3/library/target/scala-library-bootstrapped/scala-library-3.8.2-RC1-bin-SNAPSHOT.jar tests/pos/i24750.scala
[success] Total time: 7 s, completed Jan 16, 2026, 5:34:38 PM
sbt:scala3-bootstrapped> project scala3-nonbootstrapped
[info] set current project to scala3-nonbootstrapped (in build file:/home/amarki/projects/scala3/)
sbt:scala3-nonbootstrapped> scalac tests/pos/i24750.scala
[info] running (fork) dotty.tools.dotc.Main -d /home/amarki/projects/scala3/out/default-last-scalac-out.jar -classpath /home/amarki/projects/scala3/library/target/scala-library-nonbootstrapped/scala-library-3.8.2-RC1-bin-SNAPSHOT-nonbootstrapped.jar tests/pos/i24750.scala
-- [E029] Pattern Match Exhaustivity Warning: tests/pos/i24750.scala:7:13 ------
7 |    duration.unit match
  |    ^^^^^^^^^^^^^
  |match may not be exhaustive.
  |
  |It would fail on pattern case: NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS
  |(More unmatched cases are elided)
  |
  | longer explanation available when compiling with `-explain`
1 warning found
[success] Total time: 5 s, completed Jan 16, 2026, 5:35:01 PM

av.visitEnum(name, edesc, evalue)
// Handle final val aliases to Java enum values.
// Check if the symbol's pre-erasure type was a singleton of a Java enum value.
case t: tpd.RefTree if atPhase(erasurePhase) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there is a reason to prefer atPhaseBeforeTransforms or conversely to avoid it.

I see to my chagrin that braceless colon syntax does not work, atPhaseBeforeTransforms:.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

"Better you than me!"

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.

Match exhaustivity warning when matching scala.concurrent.duration.MILLISECONDS and more Final val of Java enum is not a constant value

2 participants