question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scala 3 Derive Macro Compiler Error

See original GitHub issue

Dependencies:


scalaVersion := "3.1.3"

libraryDependencies ++= Seq(
      "org.sangria-graphql"  %% "sangria"             % "3.3.0-RC1",
      "org.sangria-graphql"  %% "sangria-circe"       % "1.3.2",
      "io.circe"             %% "circe-parser"        % "0.14.2",
      "io.circe"             %% "circe-generic"       % "0.14.2",
    )

Code:

import sangria.schema.ObjectType
import scala.concurrent.Future
import sangria.schema.InputObjectType

case class Ctx(ctx: String)

object PostSchema {
  import sangria.marshalling.circe._
  import io.circe.generic.auto._
  import sangria.macros.derive._

  case class UpdatePostGql() {
    @GraphQLField
    def text(text: TextInputGql): Future[String] = ???
  }

  object UpdatePostGql{
    implicit val _ot: ObjectType[Ctx, UpdatePostGql] =
      deriveObjectType[Ctx, UpdatePostGql](
        ObjectTypeName("UpdatePost")
      )
  }

  case class TextInputGql(text: String)

  object TextInputGql{
    implicit val _it: InputObjectType[TextInputGql] =
      deriveInputObjectType[TextInputGql](
        InputObjectTypeName("TextInput")
      )
  }
}

Error:

[error] -- Error: {path}\src\main\scala\PostSchema.scala:35:42
[error] 35 |      deriveObjectType[Ctx, UpdatePostGql](
[error]    |      ^
[error]    |Exception occurred while executing macro expansion.
[error]    |scala.MatchError: OrType(AndType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class schema)),module class PostSchema$)),class TextInputGql),AppliedType(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class sangria)),object util),tag),type Tagged),List(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class sangria)),object marshalling),FromInput),InputObjectResult)))),TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Null)) (of class dotty.tools.dotc.core.Types$CachedOrType)
[error]    |    at dotty.tools.dotc.transform.TypeUtils$.companionRef(TypeUtils.scala:91)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.companionPath(Synthesizer.scala:252)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.productMirror(Synthesizer.scala:311)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$6$$anonfun$1$$anonfun$1$$anonfun$1(Synthesizer.scala:396)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.makeMirror(Synthesizer.scala:388)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$6$$anonfun$1(Synthesizer.scala:396)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$8$$anonfun$1(Synthesizer.scala:413)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.recur$1(Synthesizer.scala:556)
[error]    |    at dotty.tools.dotc.typer.Synthesizer.tryAll(Synthesizer.scala:561)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:857)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3451)
[error]    |    at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3487)
[error]    |    at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3563)
[error]    |    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3761)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3995)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
[error]    |    at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:3340)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3982)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
[error]    |    at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1053)
[error]    |    at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1173)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1272)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1442)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1470)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1503)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:997)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:851)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3451)
[error]    |    at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3487)
[error]    |    at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3563)
[error]    |    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3761)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3995)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
[error]    |    at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:3340)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3982)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
[error]    |    at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1053)
[error]    |    at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1173)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1272)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1442)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1470)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1478)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1503)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:997)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:851)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3451)
[error]    |    at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3487)
[error]    |    at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3563)
[error]    |    at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3761)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3995)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
[error]    |    at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:3340)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3982)
[error]    |    at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3329)
[error]    |    at dotty.tools.dotc.typer.Implicits.typedImplicit(Implicits.scala:1053)
[error]    |    at dotty.tools.dotc.typer.Implicits.typedImplicit$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.typedImplicit(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.tryImplicit(Implicits.scala:1173)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.rank$1(Implicits.scala:1272)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1442)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1470)
[error]    |    at dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1503)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:997)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:117)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:851)
[error]    |    at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:785)
[error]    |    at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:117)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$Implicits$.search(QuotesImpl.scala:2396)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$Implicits$.search(QuotesImpl.scala:2395)
[error]    |    at scala.quoted.Expr$.summon(Expr.scala:232)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.createArg(DeriveObjectTypeMacro.scala:429)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.$anonfun$237$$anonfun$1(DeriveObjectTypeMacro.scala:299)
[error]    |    at scala.collection.immutable.List.map(List.scala:246)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.$anonfun$237(DeriveObjectTypeMacro.scala:299)
[error]    |    at scala.collection.immutable.List.map(List.scala:246)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.fieldWithArguments(DeriveObjectTypeMacro.scala:299)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.$anonfun$228(DeriveObjectTypeMacro.scala:171)
[error]    |    at scala.collection.immutable.List.map(List.scala:246)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.collectFields(DeriveObjectTypeMacro.scala:254)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro.deriveObjectType(DeriveObjectTypeMacro.scala:72)
[error]    |    at sangria.macros.derive.DeriveObjectTypeMacro$.deriveNormalObjectType(DeriveObjectTypeMacro.scala:45)
[error]    |
[error] 36 |        ObjectTypeName("UpdatePost")
[error] 37 |      )
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from package.scala:14
[error]     ----------------------------------------------------------------------------
[error] one error found

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jchybcommented, Aug 30, 2022

I am taking a look at this right now, and I feel I am close to figuring this out. Slightly delaying implicit resolution in macro seems to make errors consistent between code with import io.circe.generic.auto._ and without it in the first snippet (no idea why yet). It still errors, but at least without the ugly dotc stack trace, just errors with failed implicit resolution. Those suggest that I might need to check what is going on in the sangria.marshalling.circe module. I’ll try to prepare a PR with the fixes after figuring out the rest.

0reactions
PsyfireXcommented, Aug 31, 2022

@jchyb Thank you! I believe this is the very last piece in order for me to finish converting my entire project over to Scala 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Class Derivation in Scala 3
Otherwise we get a compile error. The summonAll function will be used by the algorithm for both enums, going from (RegisteredUser, AnonymousUser) ...
Read more >
Type Class Derivation
Type class derivation is a way to automatically generate given instances for type classes which satisfy some simple conditions. A type class in...
Read more >
Use Scala 3 derivation instead of Magnolia for Scala 3 #434
Magnolia is moving quite slowly, and I think that I can implement all of it's functionality using Scala 3's auto derivation + a...
Read more >
Scala 3 macros tips & tricks
The inline modifier instructs the compiler to evaluate the code at compile-time. This includes expanding inline def method definitions, ...
Read more >
How to write a type class `derived` method using macros
The low-level method we will use to implement the derived method exploits quotes, splices of both expressions and types and the scala.quoted.Expr.summon method ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found