Scala 3: fails to wire constructor param with implicit lookup

I recently migrated my app to Scala 3 and started seeing the following error with Macwire.

class SlickProductRepository extends ProductRepository[DBIO] { }

class ProductService[F[_], DB[_]: Monad](
  repository: ProductRepository[DB], 
  dbManager: DatabaseManager[F, DB]
)

import slick.dbio.*
import foo.bar.DBIOInstances.* 
trait MainModule {

lazy val dbManager: SlickDatabaseManager       = wire[SlickDatabaseManager]

lazy val productRepository = wire[SlickProductRepository]
lazy val productService    = wire[ProductService[Future, DBIO]] // fails

}

I am using slick-cats to get a Monad[DBIO]. Since the lib doesn’t have a Scala 3 version yet, I copied the source to my project and imported the relevant implicits to MainModule

Error log

[error] -- Error: /project-name/src/main/scala/foo/bar/MainModule.scala:45:36 
[error] 45 |  lazy val productService     = wire[ProductService[Future, DBIO]]
[error]    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |Exception occurred while executing macro expansion.
[error]    |java.lang.AssertionError: assertion failed
[error]    |    at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:444)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:443)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.paramType(ConstructorCrimper.scala:92)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.wireConstructorParamsWithImplicitLookups$$anonfun$4$$anonfun$3(ConstructorCrimper.scala:75)
[error]    |    at scala.collection.immutable.List.map(List.scala:246)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.wireConstructorParamsWithImplicitLookups$$anonfun$1(ConstructorCrimper.scala:75)
[error]    |    at scala.collection.immutable.List.map(List.scala:246)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.wireConstructorParamsWithImplicitLookups(ConstructorCrimper.scala:76)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.constructorArgs$$anonfun$3$$anonfun$1(ConstructorCrimper.scala:57)
[error]    |    at scala.Option.map(Option.scala:242)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.constructorArgs$$anonfun$2(ConstructorCrimper.scala:57)
[error]    |    at com.softwaremill.macwire.internals.Logger.withBlock(Logger.scala:15)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.constructorArgs(ConstructorCrimper.scala:58)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.constructorTree$$anonfun$5$$anonfun$3(ConstructorCrimper.scala:63)
[error]    |    at scala.Option.flatMap(Option.scala:283)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.constructorTree$$anonfun$2(ConstructorCrimper.scala:67)
[error]    |    at com.softwaremill.macwire.internals.Logger.withBlock(Logger.scala:15)
[error]    |    at com.softwaremill.macwire.internals.ConstructorCrimper.constructorTree(ConstructorCrimper.scala:68)
[error]    |    at com.softwaremill.macwire.MacwireMacros$.wire(MacwireMacros.scala:54)
[error]    |    at com.softwaremill.macwire.MacwireMacros$.wireImpl(MacwireMacros.scala:14)
[error]    |
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from package.scala:4
[error]     ----------------------------------------------------------------------------
[error] one error found

Is this a known issue, or am I missing something? Can someone help me with this?

Not an issue I’m aware of - but we’d need a reproducing, small example to say anything more.

1 Like

@adamw Here is a minimal example that reproduces this issue

Here’s a minimized example:

import com.softwaremill.macwire.wire

type DBIO[T]
class ProductService[DB[_]]

trait MainModule {
  lazy val productService = wire[ProductService[DBIO]]
}

It seems this comes from: macwire/macros/src/main/scala-3/com/softwaremill/macwire/internals/ConstructorCrimper.scala at 02fb451a8af4396d7880f81dbbccea5ec919818e · softwaremill/macwire · GitHub

We should probably add special handling for type parameters. Can you maybe create a GH issue for that? (And maybe a PR :slight_smile: )

Thanks for debugging it further. I’ll open an issue and see if I can fix it.