Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use implicits with type projections in implicit macros #7959

Open
scabug opened this issue Nov 8, 2013 · 2 comments
Open

Cannot use implicits with type projections in implicit macros #7959

scabug opened this issue Nov 8, 2013 · 2 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Nov 8, 2013

Requesting an implicit parameter using a type projection does not work in an implicit macro. The following macro cannot be resolved implicitly at the call site:

  implicit def jdbcType[E <: AutoMappedJdbcTypeBase](implicit ct: ClassTag[E], jt: JdbcType[E#Underlying]): JdbcType[E] with BaseTypedType[E] =
    macro AutoMappedJdbcType.applyMacroImpl[E]

  def applyMacroImpl[E <: AutoMappedJdbcTypeBase](c: Context)(ct: c.Expr[ClassTag[E]], jt: c.Expr[JdbcType[E#Underlying]])(implicit e: c.WeakTypeTag[E], eu: c.WeakTypeTag[E#Underlying]): c.Expr[JdbcType[E] with BaseTypedType[E]] = ...

Replacing "macro AutoMappedJdbcType.applyMacroImpl[ E ]" with "???", thus turning it into a regular implicit method, makes the call site compile.

-Xshow-implicits gives the following details:

[info] /Users/szeiger/code/slick/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala:344: materializing requested scala.reflect.type.ClassTag[ID] using `package`.this.materializeClassTag[ID]()
[info]       def id = column[ID]("id", O.PrimaryKey)
[info]                          ^
[info] /Users/szeiger/code/slick/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala:344: jdbc.this.AutoMappedJdbcType.jdbcType is not a valid implicit value for scala.slick.ast.TypedType[ID] because:
[info] exception during macro expansion:
[info] java.lang.IllegalArgumentException: wrong number of arguments
[info]       def id = column[ID]("id", O.PrimaryKey)
[info]                          ^
[error] /Users/szeiger/code/slick/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala:344: could not find implicit value for parameter tm: scala.slick.ast.TypedType[ID]
[error]       def id = column[ID]("id", O.PrimaryKey)
[error]                          ^
[error] one error found

Trying to pass the type projection as a separate type argument to the macro, fails as well:

  implicit def jdbcType[E <: AutoMappedJdbcTypeBase](implicit ct: ClassTag[E], jt: JdbcType[E#Underlying]): JdbcType[E] with BaseTypedType[E] =
    macro AutoMappedJdbcType.applyMacroImpl[E, E#Underlying]

  def applyMacroImpl[E <: AutoMappedJdbcTypeBase, U](c: Context)(ct: c.Expr[ClassTag[E]], jt: c.Expr[JdbcType[U]])(implicit e: c.WeakTypeTag[E], eu: c.WeakTypeTag[U]): c.Expr[JdbcType[E] with BaseTypedType[E]] = ...

In this case, the error shown by -Xshow-implicits is:

[info] /Users/szeiger/code/slick/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala:319: materializing requested scala.reflect.type.ClassTag[ID] using `package`.this.materializeClassTag[ID]()
[info]       def id = column[ID]("id", O.PrimaryKey)
[info]                          ^
[info] /Users/szeiger/code/slick/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala:319: jdbc.this.AutoMappedJdbcType.jdbcType is not a valid implicit value for scala.slick.ast.TypedType[ID] because:
[info] hasMatchingSymbol reported error: type mismatch;
[info]  found   : AutoMappedJdbcTypeBase.this.Underlying
[info]  required: Int
[info]       def id = column[ID]("id", O.PrimaryKey)
[info]                          ^
[error] /Users/szeiger/code/slick/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala:319: could not find implicit value for parameter tm: scala.slick.ast.TypedType[ID]
[error]       def id = column[ID]("id", O.PrimaryKey)
[error]                          ^
[error] one error found
@scabug
Copy link
Author

scabug commented Nov 8, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7959?orig=1
Reporter: @szeiger
Affected Versions: 2.10.3, 2.11.0-M6

@scabug scabug added the macros label Apr 7, 2017
@SethTisue SethTisue added this to the Backlog milestone Mar 2, 2018
@SethTisue
Copy link
Member

@szeiger should this stay open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants