Scala cake-pattern compile error with Precog config pattern

前端 未结 2 2018
[愿得一人]
[愿得一人] 2021-01-19 16:37

Following from this question, I have now the following:

case class Pet(val name: String)

trait ConfigComponent {
          


        
2条回答
  •  情话喂你
    2021-01-19 16:49

    What you've written should work, but doesn't, because of this bug.

    There are a number of workarounds you could use. Adding type Config = PetStoreConfig with AnotherConfig to your module implementation is probably a little less unpleasant than casting.

    Update: As som-snytt notes in a comment and answer, adding with PetStoreModuleImpl (crucially not with PetStoreModule, as you might expect) to the end of the self-type is a better solution.

    As a footnote: as discussed in the comments on SI-7255, the Dependent Object Types calculus (which is designed to be "a new foundation for Scala's type system") will address this "fundamental problem in Scala's type system".

提交回复
热议问题