Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Compilation fail using a case class with no parameters #124

@alvarogimenez

Description

@alvarogimenez

I'm getting an ambiguous implicit values compilation error when using the @reader annotation in a case class without parameters in combination with the @readers annotation over a case class with more than one parameter.

I've got this error reproduced by modifying the test ReadersNestedMacroTest, included in the last release, with the following changes:

  1. Add a new service annotated with @reader represented by a case class with no parameters
@reader
case class SomeServiceWithoutParameters()

@reader
case class WebApplication(someService: SomeService, emptyService: SomeServiceWithoutParameters)
  1. Add an additional parameter to the ApplicationConfiguration case class, which uses the @readers annotation:
case class AdditionalConfig(config3: String)

@readers
case class ApplicationConfiguration(httpConfig: HttpConfig, additionalConfig: AdditionalConfig)

Step (2.) is important since adding a new parameter to this case class seems to reproduce the error while leaving it with only one parameter results in a successful compilation.

The full test code causing the compilation error would be:

package org.zalando.grafter.macros


@readers
case class ApplicationConfiguration(httpConfig: HttpConfig, additionalConfig: AdditionalConfig)

/**
 * For a nested configuration you need to annotate the nested elements with the @readers annotation
 * as well
 */
@readers
case class HttpConfig(cfg1: HttpSubConfig1, cfg2: HttpSubConfig2 )

case class HttpSubConfig1(port: Int)
case class HttpSubConfig2(host: String)
case class AdditionalConfig(config3: String)

@reader
case class HttpClient(config: HttpSubConfig2)


@reader
case class SomeService(client: HttpClient)

@reader
case class SomeServiceWithoutParameters()

@reader
case class WebApplication(someService: SomeService, emptyService: SomeServiceWithoutParameters)


object MyApp extends App {

  val config = ApplicationConfiguration(HttpConfig(HttpSubConfig1(80), HttpSubConfig2("bla")), AdditionalConfig("3"))

  val app = WebApplication.reader[ApplicationConfiguration].apply(config)

}

And the compilation error trace when executing sbt clean test is:

[error] .../grafter/macros/src/test/scala/org/zalando/grafter/macros/ReadersNestedMacroTest.scala:36:34: ambiguous implicit values:
[error]  both method reader in object SomeServiceWithoutParameters of type [A3]=> cats.data.Reader[A3,org.zalando.grafter.macros.SomeServiceWithoutParameters]
[error]  and method transitiveadditionalConfigReader in object ApplicationConfiguration of type [A](implicit r1: cats.data.Reader[org.zalando.grafter.macros.AdditionalConfig,A], implicit r2: cats.data.Reader[org.zalando.grafter.macros.ApplicationConfiguration,org.zalando.grafter.macros.AdditionalConfig])cats.data.Reader[org.zalando.grafter.macros.ApplicationConfiguration,A]
[error]  match expected type cats.data.Reader[org.zalando.grafter.macros.ApplicationConfiguration,org.zalando.grafter.macros.SomeServiceWithoutParameters]
[error]   val app = WebApplication.reader[ApplicationConfiguration].apply(config)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions