21170

Illegal inheritance while extending trait with self type

Question:

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:

<blockquote>

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

</blockquote>

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?

Answer1:

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

Answer2:

T2 has a self type T1, which means, that every class/object/trait inheriting from T2 has to be if type T1, so in your case

object O extens T1 with T2 { type S = Whatever }

should work.

Recommend

  • Instantiate subclass from superclass
  • Is it possible to clear the console tab during runtime in Intellij with Java?
  • Read a variable from a text file
  • “The parameter type `C` may not live long enough”, when it doesn't need to
  • How to populate the modified_by with the user_id of who made the update to the record using laravel
  • Cast While Looping Over Dictionary in Swift
  • CSS overflow with long URL
  • Set which rows to delete on mysql after applying combined unique index w/ignore
  • How do I use Java generic wildcards with methods taking more than one generic parameter?
  • How to initialize global variable at each class invocation?
  • Selecting a Random Subset in SQL (Sybase Server IQ)
  • SQL complicated recursive CTE
  • Insert Path of a file with \\\\ in mysql using java
  • what is side-cast or cross-cast in Dynamic_cast in C++
  • Illegal reflective access operation
  • date: illegal option — d, Find difference between two dates
  • How do I include screenshots of the full page in my serenity report (and not only of the viewport) u
  • Understanding Intl.DateTimeFormat as a JavaScript object
  • Scala: Function returning an unknown type
  • Git describe fails to return most recent annotated tag
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Highlight and Bold text in JTextPane
  • NHibernate Validation Localization with S#arp Architecture
  • Asynchronous UI Testing in Xcode With Swift
  • how to do an event when i swipe from fragment to the other
  • How can I send an e-mail from a vbs script
  • Accessing IRQ description array within a module and displaying action names
  • angularjs unit test when to use $rootScope.$new()
  • Akka Routing: Reply's send to router ends up as dead letters
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • Getting Messege Twice Using IMvxMessenger
  • Linking SubReports Without LinkChild/LinkMaster
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • JaxB to read class hierarchy