Skip to content

Add NotGiven compatibility module#180

Open
bpholt wants to merge 10 commits into
typelevel:mainfrom
Dwolla:notgiven
Open

Add NotGiven compatibility module#180
bpholt wants to merge 10 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
@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
.settings(
name := "scalac-compat-features",
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-collection-compat" % "2.14.0" % Test,

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.

@bpholt ,
you can simply
import org.typelevel.scalaccompat.annotation.unused
And then use that unused in NotGivenSuite.

It is defined in this repository and provided by sbt-typelevel automatically. So no need for "scala-collection-compat" whatsoever.

* limitations under the License.
*/

package other.org.typelevel.scalaccompat.scala.util

@satorg satorg Jun 26, 2026

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 guess the reason for this package name is to avoid sharing the package between NotGiven implementation and its tests, correct?

Since it is about tests only, we could simply name package tests and put the file into feature/src/test/scala/tests directory – it would be short and clear, I think. Or package other, if you like it better.

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.

Just to clarify: it isn't really important, but when I open the project in IntelliJ IDEA, it complains that package other.org.typelevel.scalaccompat.scala.util doesn't correspond to the directory path. Of course, it doesn't affect the build itself, but I don't see a reason why we have to introduce such a discrepancy. We could move the tests into ".../other/org/typelevel/scalaccompat/scala/util" directory, but for the tests it doesn't have to be that long either – a short "tests" or "other" or whatever will do the job, I guess.

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