apply a Mixin to a class

138 views
Skip to first unread message

Bluenuance

unread,
Mar 21, 2013, 8:30:48 AM3/21/13
to mi...@dartlang.org
toying around with Mixins and got me into some trouble (or is it just an editor bug?)

this is the code I tried first:

class Person with Actor implements Moveable {....}



this is refused with the message
"The with clause cannot be used without an extends clause"


but when I change it to:

class Person extends Object with Actor implements Moveable {....}


its fine....
I'm confused if this is simply a bug or...?

Ladislav Thon

unread,
Mar 21, 2013, 9:06:44 AM3/21/13
to mi...@dartlang.org
It's correct. IMHO, the syntax is a bit unfortunate, but there's a simple advice, which is actually semantically correct: in the declaration class C extends SC with M1, M2, M3 implements I1, I2 { ... }, imagine parenthesis around the content of the extends clause. They will look like this: class C extends (SC with M1, M2, M3) implements I1, I2 { ... }. Which means that class C doesn't extend SC, it extends SC_with_M1_with_M2_with_M3.

Or, put another way: the class declaration has an extends clause and an implements clause, but it doesn't have a with clause. Instead, the with clause belongs inside the extends clause.

LT

Bluenuance

unread,
Mar 21, 2013, 9:22:42 AM3/21/13
to mi...@dartlang.org
ah I see, your tip with the parenthesis made me understand it much better, thanks.
(so much I wouldn't mind if it would be forced at all ;)  )

Andrei Mouravski

unread,
Mar 21, 2013, 4:48:25 PM3/21/13
to General Dart Discussion
It's correct. IMHO, the syntax is a bit unfortunate, but there's a simple advice, which is actually semantically correct: in the declaration class C extends SC with M1, M2, M3 implements I1, I2 { ... }, imagine parenthesis around the content of the extends clause. They will look like this: class C extends (SC with M1, M2, M3) implements I1, I2 { ... }. Which means that class C doesn't extend SC, it extends SC_with_M1_with_M2_with_M3.

Or, put another way: the class declaration has an extends clause and an implements clause, but it doesn't have a with clause. Instead, the with clause belongs inside the extends clause.

Wow. Now I understand this so much better. Thanks for the great explanation!
Reply all
Reply to author
Forward
0 new messages