Value does not comply with type parameter restrictions

I'm having type problems. In this case, I have two traits with basic methods, and one of them depends on the other. After that, I have two implementations for them. You do not know what is wrong here?

The compiler says:

type arguments [ImplDefinition,ImplDto,ImplDtoIdentifier] do not conform to trait ChildOperations type parameter bounds [C <: Types.BaseT[A,I],A <: Types.IDObj[I],I <: IIdentifier] [error] class ImplOperations extends Parent2(new ImplDefinition) with ChildOperations[ImplDefinition, ImplDto, ImplDtoIdentifier] { 

Code:

 /* * Generic Implementation */ object Types { type IDObj[I <: IIdentifier] = AnyRef {def id: I} type BaseT[A, I <: IIdentifier] = Parent1[A] { def id: Foo[I] } } trait IIdentifier extends Any { def id: Long override def toString = id.toString } class Parent1[A](a: String) class Foo[A](a: String) trait ChildDefinition[A <: Types.IDObj[I], I <: IIdentifier] { self: Parent1[A] => def id(a: A): Foo[I] } class Parent2[A](a: A) trait ChildOperations[C <: Types.BaseT[A, I], A <: Types.IDObj[I], I <: IIdentifier] { self: Parent2[C] => def get(identifier: I): Option[A] } /* * Concrete Implementation */ case class ImplDtoIdentifier(id: Long) extends IIdentifier case class ImplDto(id: ImplDtoIdentifier, name: String) class ImplDefinition extends Parent1[ImplDto]("Value") with ChildDefinition[ImplDto, ImplDtoIdentifier] { override def id(a: ImplDto): Foo[ImplDtoIdentifier] = ??? } class ImplOperations extends Parent2(new ImplDefinition) with ChildOperations[ImplDefinition, ImplDto, ImplDtoIdentifier] { self => override def get(identifier: ImplDtoIdentifier): Option[ImplDto] = ??? // here I will use the id method from ImplDefinition } 
+5
source share
1 answer

the problem seems to be the id def signature in ImplDefinition . Types.BaseT asks for def id: Foo[I] , but ImplDefinition provides only def id(a: ImplDto): Foo[ImplDtoIdentifier] if you add def id:Foo[ImplDtoIdentifier] = ??? into the ImplDefinition class, then things will compile:

 class ImplDefinition extends Parent1[ImplDto]("Value") with ChildDefinition[ImplDto, ImplDtoIdentifier] { def id:Foo[ImplDtoIdentifier] = ??? override def id(a: ImplDto): Foo[ImplDtoIdentifier] = ??? } 
+4
source

Source: https://habr.com/ru/post/1247461/


All Articles