Dart mixin 'with' can't be used without extensions?

I work in Webstorm 6.0.2 and get an error when trying to use mixin syntax:

class A{} class B with A{} //error can't use with syntax without an extends? 

Why can't I use with without extends ? Of course, each class is implicitly extends Object .

+7
source share
1 answer

Here's a really clear explanation from Ladislav Thon :

[...] there is a simple tip that is actually semantically correct: in the class of declaration C, SC continues with M1, M2, M3 implements I1, I2 {...}, imagine the brackets around the contents of the extensions clause. They will look like this: the class C extends (SC with M1, M2, M3) implements I1, I2 {...}. This means that class C does not extend SC; it extends SC_with_M1_with_M2_with_M3.

Or, in another way: a class declaration has an extends clause and an implements clause, but does not have a with clause. Instead, the with clause belongs inside the extends clause.

And one more point from Florian Loich :

When you extend "Object" with mixin, the first mixin can always replace "Object".

So your class B with A should be class B extends Object with A , which is also equivalent to class B extends A

+14
source

All Articles