Skip to content

Add NotGiven compatibility module#180

Merged
satorg merged 13 commits into
typelevel:mainfrom
Dwolla:notgiven
Jun 29, 2026
Merged

Add NotGiven compatibility module#180
satorg merged 13 commits into
typelevel:mainfrom
Dwolla:notgiven

Conversation

@bpholt

@bpholt bpholt commented Apr 8, 2026

Copy link
Copy Markdown
Member

Scala 3 introduced scala.util.NotGiven: a special class used to implement negation in implicit search.

While techniques existed to implement this functionality in some cases in Scala 2, the NotGiven trait was not backported to Scala 2. This makes cross-compilation more frustrating than it needs to be, so this module was created to make a single org.typelevel.scalaccompat.scala.util.NotGiven available to Scala 2.12, 2.13, and 3.

This is based on prior work by Shapeless and fs2.

This was initially proposed as typelevel/tsc#171, but I agree that this repo is a better home for this code.

@bpholt bpholt force-pushed the notgiven branch 2 times, most recently from fee9115 to 537e147 Compare April 8, 2026 22:29
@bpholt

bpholt commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

I used Jetbrains Junie in IntelliJ to add some motivating examples / tests that don't compile on Scala 2 without the new module. Hopefully that's helpful.

I'm not sure we needed to wait for that, but now that it's there, I think this is ready to be reviewed @satorg @armanbilge.

@armanbilge armanbilge requested review from armanbilge and satorg April 22, 2026 14:31
Comment thread features/src/test/scala/tests/NotGivenSuite.scala
@bpholt bpholt requested a review from armanbilge April 23, 2026 22:15
Comment thread build.sbt Outdated
@satorg

satorg commented May 14, 2026

Copy link
Copy Markdown
Contributor

@bpholt , thank you for the PR! It looks great overall, but I'd vote for naming consistency here.
The existing sub-project name is annotations and its published module name is scalac-compat-annotations.

For the new module I'd personally prefer to have something like notgiven and scalac-compat-notgiven correspondingly – just to keep the naming consistent across the project.

Moreover, for now we only get NotGiven here, but I can imagine that in the future we may want to provide cross-compiling compatibilites for other Scala3 features. How about renaming the new module into features/scalac-compat-features or utils/scalac-compat-utils? (utils – because NotGiven is in scala.util package, but features would be even more generic).

@bpholt

bpholt commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@bpholt , thank you for the PR! It looks great overall, but I'd vote for naming consistency here. The existing sub-project name is annotations and its published module name is scalac-compat-annotations.

For the new module I'd personally prefer to have something like notgiven and scalac-compat-notgiven correspondingly – just to keep the naming consistent across the project.

Moreover, for now we only get NotGiven here, but I can imagine that in the future we may want to provide cross-compiling compatibilites for other Scala3 features. How about renaming the new module into features/scalac-compat-features or utils/scalac-compat-utils? (utils – because NotGiven is in scala.util package, but features would be even more generic).

Makes sense! I updated this in a05e47e.

@bpholt bpholt requested a review from satorg June 2, 2026 23:02
Comment thread build.sbt Outdated
Comment thread features/src/test/scala/org/typelevel/scalaccompat/scala/util/NotGivenSuite.scala Outdated

@satorg satorg 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.

Thank you!

@bpholt

bpholt commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@armanbilge did you want to take another look, or shall we go ahead and merge?

@armanbilge armanbilge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for seeing this through!

@satorg satorg merged commit 821ab9f into typelevel:main Jun 29, 2026
11 checks passed
@bpholt bpholt deleted the notgiven branch June 29, 2026 21:22
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.

3 participants