Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal inheritance while extending trait with self type

Tags:

scala

I'm confused by the following code:

    trait T1 {
        type S
    }

    trait T2 {
      self: T1 =>

       case  class ClS(s: S)
    }

    object O extends T2 {

    }

It gives out the following error message:

illegal inheritance; tests.O.type does not conform to tests.T2's selftype tests.T2 with tests.T1

What's going wrong? the reason that I extend O with T2 is that I want to reference the class CLS in O, how can I achieve that?

like image 719
monica Avatar asked Feb 19 '13 07:02

monica


1 Answers

trait T2 has a contract that says: If you inherit from me, you should also inherit from T1.

object O extends T2 with T1

You would then probably get an error that type S is not defined. Which is a good thing since it's used in the definition of CLS

like image 93
EECOLOR Avatar answered Sep 26 '22 21:09

EECOLOR