Skip to content

Add Scala 3 code generation support (#2188)#2196

Open
Tanveer17 wants to merge 1 commit intomasterfrom
scala3-codegen
Open

Add Scala 3 code generation support (#2188)#2196
Tanveer17 wants to merge 1 commit intomasterfrom
scala3-codegen

Conversation

@Tanveer17
Copy link

Summary

  • Add ScalaVersion ADT to represent target Scala version (2.12, 2.13, 3)
  • Add Scala3Compat utility for generating using clauses instead of implicit for Scala 3
  • Add scalaVersion field to Context for version-aware code generation
  • Update AkkaHttp generators to use Scala3Compat.implicitsClause
  • Update Http4s client generator for Scala 3 compatibility

Closes #2188

Test plan

  • Unit tests for ScalaVersion parsing and behavior (16 tests)
  • Unit tests for Scala3Compat clause generation (13 tests)
  • Unit tests verifying generated server code uses using for Scala 3 (5 tests)
  • Unit tests verifying generated client code uses using for Scala 3 (4 tests)

Notes on Integration Testing

The current unit tests verify the AST structure contains correct using/implicit syntax based on Scala version. Full compilation-based integration testing (via
modules/sample-*) would require adding Scala 3 to the build infrastructure, as sample modules currently only compile with Scala 2.12/2.13.

Options for future work:

  1. Add a single sample-scala3 module to validate compilation
  2. Cross-compile existing samples with Scala 3

Happy to discuss the best approach for integration testing infrastructure.

Related PRs

  • sbt-guardrail: Threading scalaVersion parameter (pending)
  • module-pekko-http: Scala 3 support for Pekko HTTP generators (pending)

- Add ScalaVersion ADT to represent target Scala version (2.12, 2.13, 3)
- Add Scala3Compat utility for generating `using` clauses instead of `implicit`
- Add scalaVersion field to Context for version-aware code generation
- Update AkkaHttp generators to use Scala3Compat.implicitsClause
- Update Http4s client generator for Scala 3 compatibility
- Add comprehensive tests for ScalaVersion, Scala3Compat, and generated code
@Tanveer17 Tanveer17 added scala-akka-http Pertains to guardrail-scala-akka-http scala-http4s Pertains to guardrail-scala-http4s scala-support Pertains to guardrail-scala-support core Pertains to guardrail-core minor Bump minor version cli Pertains to guardrail-cli labels Dec 8, 2025
@Tanveer17 Tanveer17 self-assigned this Dec 8, 2025
@blast-hardcheese blast-hardcheese added major Bump major version and removed minor Bump minor version labels Dec 21, 2025
Copy link
Member

@blast-hardcheese blast-hardcheese left a comment

Choose a reason for hiding this comment

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

phenomenal. Pardon my delay on review, I've been quite sick over the past week.

I've adjusted this to be a major bump to make the release simpler. We've been on RC for over a year while the module system burned in, which ended up also scope creeping in my head to also improving the ergonomics for the client codegen, but I think it'll actually be both easier and more sensible to just release a revised client API with a standard deprecation cycle (interfaces annotated with @deprecated, 2.x to drop the deprecated client API)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Pertains to guardrail-cli core Pertains to guardrail-core major Bump major version scala-akka-http Pertains to guardrail-scala-akka-http scala-http4s Pertains to guardrail-scala-http4s scala-support Pertains to guardrail-scala-support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Scala 3 Code Generation Support

3 participants