diff --git a/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala b/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala index b5f2da90..95db97a5 100644 --- a/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala +++ b/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala @@ -21,7 +21,6 @@ package org.scalamock.clazz import org.scalamock.context.MockContext - import scala.quoted.* import scala.reflect.Selectable @@ -42,8 +41,13 @@ private[clazz] object MockMaker: def asParent(tree: TypeTree): TypeTree | Term = val constructorFieldsFilledWithNulls: List[List[Term]] = tree.tpe.dealias.typeSymbol.primaryConstructor.paramSymss - .filter(_.exists(!_.isType)) - .map(_.map(_.typeRef.asType match { case '[t] => '{ null.asInstanceOf[t] }.asTerm })) + .filterNot(_.exists(_.isType)) + .map(_.map(_.info.widen match { + case t@AppliedType(inner, applied) => + Select.unique('{null}.asTerm, "asInstanceOf").appliedToTypes(List(inner.appliedTo(tpe.typeArgs))) + case other => + Select.unique('{null}.asTerm, "asInstanceOf").appliedToTypes(List(other)) + })) if constructorFieldsFilledWithNulls.forall(_.isEmpty) then tree @@ -51,7 +55,9 @@ private[clazz] object MockMaker: Select( New(TypeIdent(tree.tpe.typeSymbol)), tree.tpe.typeSymbol.primaryConstructor - ).appliedToArgss(constructorFieldsFilledWithNulls) + ).appliedToTypes(tree.tpe.typeArgs) + .appliedToArgss(constructorFieldsFilledWithNulls) + val parents = diff --git a/shared/src/test/scala-3/com/paulbutcher/test/ClassWithContextBoundSpec.scala b/shared/src/test/scala-3/com/paulbutcher/test/ClassWithContextBoundSpec.scala new file mode 100644 index 00000000..67066c60 --- /dev/null +++ b/shared/src/test/scala-3/com/paulbutcher/test/ClassWithContextBoundSpec.scala @@ -0,0 +1,37 @@ +package com.paulbutcher.test + +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec + +import scala.reflect.ClassTag + +class ClassWithContextBoundSpec extends AnyFunSpec with MockFactory { + + it("compile without args") { + class ContextBounded[T: ClassTag] { + def method(x: Int): Unit = () + } + + val m = mock[ContextBounded[String]] + + } + + it("compile with args") { + class ContextBounded[T: ClassTag](x: Int) { + def method(x: Int): Unit = () + } + + val m = mock[ContextBounded[String]] + + } + + it("compile with provided explicitly type class") { + class ContextBounded[T](x: ClassTag[T]) { + def method(x: Int): Unit = () + } + + val m = mock[ContextBounded[String]] + + } + +}