Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@jchyb
Copy link

@jchyb jchyb commented Jul 15, 2025

Includes scala-2 and scala-3 versions of the macros. For scala-2, the old one was brought back, but for scala-3, the api had to be adjusted to comply with the new type projection rules. This difference in API should not matter that much, as this is an implicit method. The test were brought back from #2698
The -source 3.0-migration option had to be removed as it caused the added macro to not compile. This in turn caused more warnings to be thrown, most of them being a variation of pattern's type (...) is more specialized than the right hand side expression's type (...) (which were suppressed in the second commit).

jchyb added 2 commits July 15, 2025 12:33
Includes scala-2 and scala-3 versions of the macros. For scala-2,
the old one was brought back, but for scala-3, the api had to be
adjusted to comply with the new type projection rules. This difference
in API should not matter that much, as this is an implicit method.
The -source 3.0-migration option had to be removed as it caused the
added macro to not compile.
@nafg nafg requested a review from Copilot July 15, 2025 14:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Restore and unify support for MappedTo-based column mapping across Scala 2 and Scala 3, adjust related implicits and APIs, and re-enable corresponding tests

  • Reintroduce Scala-2 and Scala-3 MappedTo and Isomorphism macros
  • Add isomorphicType implicit in RelationalImplicitColumnTypes and new MappedTo[String] extension methods
  • Suppress newly surfaced pattern-match warnings with : @unchecked across several compiler/driver components and restore lifted-mapping tests

Reviewed Changes

Copilot reviewed 18 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
slick/src/main/scala/slick/relational/RelationalProfile.scala Added isomorphicType implicit for automatic column mapping
slick/src/main/scala/slick/lifted/ExtensionMethods.scala Added MappedTo[String] and Option[MappedTo[String]] string methods
slick/src/main/scala/slick/lifted/Aliases.scala Introduced MappedTo and Isomorphism type aliases
slick/src/main/scala-3/slick/lifted/MappedTo.scala New Scala 3 macro implementation for MappedTo isomorphism
slick/src/main/scala-2/slick/lifted/MappedTo.scala Restored Scala 2 macro implementation for MappedTo isomorphism
slick/src/main/scala/slick/memory/DistributedProfile.scala Wrapped pattern matches in : @unchecked to suppress warnings
slick/src/main/scala/slick/jdbc/JdbcStatementBuilderComponent.scala Added : @unchecked on result of forceInsertCompiler.run(...)
slick/src/main/scala/slick/jdbc/JdbcInvokerComponent.scala Added : @unchecked in findCompiledStatement destructuring
slick/src/main/scala/slick/jdbc/JdbcActionComponent.scala Added : @unchecked on CompiledMapping destructuring
slick/src/main/scala/slick/compiler/*.scala Added : @unchecked on various pattern-match destructurings
slick-testkit/src/test/scala/slick/test/lifted/MappedToStringExtensionMethodSupportTest.scala Added tests covering string methods on MappedTo[String]
slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/RelationalMapperTest.scala Extended mapping tests with auto-mapped IDs and projection shapes
Comments suppressed due to low confidence (1)

slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/RelationalMapperTest.scala:130

  • This test method is missing an @Test annotation, so it will not be executed by the test runner. Add @Test to ensure it runs and validates the intended behavior.
  def mappedToMacroCompilerBug = {

@github-actions
Copy link
Contributor

Incompatible changes

slick

12 changes since 3.7.0-pre.103.e7dfce09

Code changes

Incompatibility Symbol Problem
Binary slick.compat.collection.package MissingClassProblem

class slick.compat.collection.package does not have a correspondent in current version

Binary slick.compat.collection.package$ MissingClassProblem

object slick.compat.collection.package does not have a correspondent in current version

Binary slick.compat.collection.package$JavaConverters$ MissingClassProblem

object slick.compat.collection.package#JavaConverters does not have a correspondent in current version

Binary slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes.slick$relational$RelationalTypesComponent$RelationalImplicitColumnTypes$$$outer ReversedMissingMethodProblem

abstract synthetic method slick$relational$RelationalTypesComponent$RelationalImplicitColumnTypes$$$outer()slick.relational.RelationalTypesComponent in interface slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes is present only in current version

Source slick.lifted.ExtensionMethodConversions.mappedToStringColumnExtensionMethods DirectMissingMethodProblem

method mappedToStringColumnExtensionMethods(slick.lifted.Rep)slick.lifted.Rep in interface slick.lifted.ExtensionMethodConversions does not have a correspondent in current version

Source slick.lifted.ExtensionMethodConversions.mappedToOptionStringColumnExtensionMethods DirectMissingMethodProblem

method mappedToOptionStringColumnExtensionMethods(slick.lifted.Rep)slick.lifted.Rep in interface slick.lifted.ExtensionMethodConversions does not have a correspondent in current version

Source slick.lifted.Isomorphism MissingClassProblem

class slick.lifted.Isomorphism does not have a correspondent in current version

Source slick.lifted.MappedTo MissingClassProblem

interface slick.lifted.MappedTo does not have a correspondent in current version

Source slick.lifted.MappedToBase MissingClassProblem

interface slick.lifted.MappedToBase does not have a correspondent in current version

Source slick.lifted.MappedToBase$ MissingClassProblem

object slick.lifted.MappedToBase does not have a correspondent in current version

Source slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes.isomorphicType DirectMissingMethodProblem

method isomorphicType(slick.lifted.Isomorphism,scala.reflect.ClassTag,slick.ast.TypedType)slick.ast.TypedType in interface slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes does not have a correspondent in current version

Source slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes.$init$ DirectMissingMethodProblem

synthetic static method $init$(slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes)Unit in interface slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes does not have a correspondent in current version

slick-testkit

5 changes since 3.7.0-pre.103.e7dfce09

Code changes

Incompatibility Symbol Problem
Source com.typesafe.slick.testkit.tests.MyMappedID MissingClassProblem

class com.typesafe.slick.testkit.tests.MyMappedID does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.MyMappedID$ MissingClassProblem

object com.typesafe.slick.testkit.tests.MyMappedID does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.RelationalMapperTest.testAutoMapped DirectMissingMethodProblem

method testAutoMapped()slick.dbio.DBIOAction in class com.typesafe.slick.testkit.tests.RelationalMapperTest does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.RelationalMapperTest.mappedToMacroCompilerBug DirectMissingMethodProblem

method mappedToMacroCompilerBug()slick.lifted.Query in class com.typesafe.slick.testkit.tests.RelationalMapperTest does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.RelationalMapperTest.testMappedProjectionShape DirectMissingMethodProblem

method testMappedProjectionShape()slick.dbio.DBIOAction in class com.typesafe.slick.testkit.tests.RelationalMapperTest does not have a correspondent in current version

@nafg
Copy link
Member

nafg commented Jul 16, 2025

What was the error with -source 3.0-migration?

@github-actions
Copy link
Contributor

Incompatible changes

slick

12 changes since 3.7.0-pre.103.e7dfce09

Code changes

Incompatibility Symbol Problem
Binary slick.compat.collection.package MissingClassProblem

class slick.compat.collection.package does not have a correspondent in current version

Binary slick.compat.collection.package$ MissingClassProblem

object slick.compat.collection.package does not have a correspondent in current version

Binary slick.compat.collection.package$JavaConverters$ MissingClassProblem

object slick.compat.collection.package#JavaConverters does not have a correspondent in current version

Binary slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes.slick$relational$RelationalTypesComponent$RelationalImplicitColumnTypes$$$outer ReversedMissingMethodProblem

abstract synthetic method slick$relational$RelationalTypesComponent$RelationalImplicitColumnTypes$$$outer()slick.relational.RelationalTypesComponent in interface slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes is present only in current version

Source slick.lifted.ExtensionMethodConversions.mappedToStringColumnExtensionMethods DirectMissingMethodProblem

method mappedToStringColumnExtensionMethods(slick.lifted.Rep)slick.lifted.Rep in interface slick.lifted.ExtensionMethodConversions does not have a correspondent in current version

Source slick.lifted.ExtensionMethodConversions.mappedToOptionStringColumnExtensionMethods DirectMissingMethodProblem

method mappedToOptionStringColumnExtensionMethods(slick.lifted.Rep)slick.lifted.Rep in interface slick.lifted.ExtensionMethodConversions does not have a correspondent in current version

Source slick.lifted.Isomorphism MissingClassProblem

class slick.lifted.Isomorphism does not have a correspondent in current version

Source slick.lifted.MappedTo MissingClassProblem

interface slick.lifted.MappedTo does not have a correspondent in current version

Source slick.lifted.MappedToBase MissingClassProblem

interface slick.lifted.MappedToBase does not have a correspondent in current version

Source slick.lifted.MappedToBase$ MissingClassProblem

object slick.lifted.MappedToBase does not have a correspondent in current version

Source slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes.isomorphicType DirectMissingMethodProblem

method isomorphicType(slick.lifted.Isomorphism,scala.reflect.ClassTag,slick.ast.TypedType)slick.ast.TypedType in interface slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes does not have a correspondent in current version

Source slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes.$init$ DirectMissingMethodProblem

synthetic static method $init$(slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes)Unit in interface slick.relational.RelationalTypesComponent#RelationalImplicitColumnTypes does not have a correspondent in current version

slick-testkit

5 changes since 3.7.0-pre.103.e7dfce09

Code changes

Incompatibility Symbol Problem
Source com.typesafe.slick.testkit.tests.MyMappedID MissingClassProblem

class com.typesafe.slick.testkit.tests.MyMappedID does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.MyMappedID$ MissingClassProblem

object com.typesafe.slick.testkit.tests.MyMappedID does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.RelationalMapperTest.testAutoMapped DirectMissingMethodProblem

method testAutoMapped()slick.dbio.DBIOAction in class com.typesafe.slick.testkit.tests.RelationalMapperTest does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.RelationalMapperTest.mappedToMacroCompilerBug DirectMissingMethodProblem

method mappedToMacroCompilerBug()slick.lifted.Query in class com.typesafe.slick.testkit.tests.RelationalMapperTest does not have a correspondent in current version

Source com.typesafe.slick.testkit.tests.RelationalMapperTest.testMappedProjectionShape DirectMissingMethodProblem

method testMappedProjectionShape()slick.dbio.DBIOAction in class com.typesafe.slick.testkit.tests.RelationalMapperTest does not have a correspondent in current version

import scala.util.control.NonFatal

/** An isomorphism between two types that can be used for mapped column types. */
class Isomorphism[A, B](val map: A => B, val comap: B => A)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the common parts could be moved to a shared source directory. Although MappedToBase would need to be in the same file as its version-dependent companion.

Copy link
Member

Choose a reason for hiding this comment

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

Is Isomorphism supposed to be instantiated by users ever or is it just an implementation detail of the macro?

If the former, perhaps it would be more ergonomic to either change the constructor, or provide an apply method, that uses two argument lists to support type inference.

Comment on lines +18 to +31
def mappedToIsomorphismMacroImpl[T: Type, E <: MappedTo[T]: Type](using Quotes): Expr[Isomorphism[E, T]] = {
import quotes.reflect._
def makeApply(v: Expr[T])(using Quotes): Expr[E] = {
import quotes.reflect._
val sym = TypeRepr.of[E].typeSymbol
Apply(Select(New(TypeTree.of[E]), sym.primaryConstructor), List(v.asTerm)).asExprOf[E]
}
val cons = '{(v: T) => ${ makeApply('v)}}

val res = '{ new Isomorphism[E, T](_.value, $cons) }
res
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Using Claude Code I came up with a version that works without changing the compiler flags:

  def mappedToIsomorphismMacroImpl[T: Type, E <: MappedTo[T]: Type](using Quotes): Expr[Isomorphism[E, T]] = {
    import quotes.reflect._
    val cons =
      Lambda(
        owner = Symbol.spliceOwner,
        tpe = MethodType(List("v"))(_ => List(TypeRepr.of[T]), _ => TypeRepr.of[E]),
        rhsFn =
          (owner, args) => {
            val sym = TypeRepr.of[E].typeSymbol
            val v = args.head.asExprOf[T]
            Apply(Select(New(TypeTree.of[E]), sym.primaryConstructor), List(v.asTerm))
          }
      ).asExprOf[T => E]

    val res = '{ new Isomorphism[E, T](_.value, $cons) }
    res
  }

I don't know macros too well but the test passes...

Do you think it's safe enough to go with and avoid needing all the other changes?

Copy link
Member

Choose a reason for hiding this comment

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

Although, maybe the other changes are net positive? What do you think?

@nafg
Copy link
Member

nafg commented Dec 1, 2025

Hi, sorry for losing sight of this for so long. Thanks for taking my comments into account. However I would appreciate if you could reply to all of them so we can figure out the best approach.

Thanks

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.

2 participants