Clarify spec of constructors which are induced implicitly by mixin application #769
Labels
bug
There is a mistake in the language specification or in an active document
specification
technical-debt
Dealing with a part of the language which needs clarification or adjustments
Section 'Mixin Application' specifies mixin applications, including the mechanism whereby the resulting class contains generative constructors which are induced implicitly. This text has a couple of imprecise elements:
$MC$
is an undefined symbol, it should be$M$
. Similarly,$C$ does not declare any instance variables
should be$M$ does not declare any instance variables
(the members declared in$M$
and in$C$
are the same, so let's stick to$M$
for consistency).The case for optional positional parameters does not allow for missing default values, and the same problem exists for named parameters (this is a tiny fix, we usually just say something like "where
$d_i$
may be omitted").<fieldFormalParameter>
(such asthis.x
) are never mentioned, but they can't occur, and we should mention that. The wordfields
is used, but not well-defined; it should beinstance variables
.It is assumed that it is possible to write an expression
$d'_i$
(which will be located in$L_C$
, that is, in the same library whereS with M
is located) such that$d'_i$
will evaluate to the same object as$d_i$
(which occurs in the the library where$S$
is declared), and this may not be possible in Dart (because of privacy). So we need to deal with the fact that this code is somewhat "magical", in the sense that it is generated by the compiler/analyzer, and they are capable of creating expressions with this property (they can break the encapsulation provided by privacy).The scoping, and in particular the treatment of private declarations in members, is unspecified. The text suggests that the declarations from
$M$
(let's call that library$L_M$
) are copied verbatim into$L_C$
, in which case private declarations in$M$
will become private to$L_C$
, and various scoping problems would arise. E.g., any use of a private identifier declared outside$M$
in the body of a declaration in$M$
would now be reinterpreted, and probably it would be an error.So we'd need to say that name resolution is not affected by the operation whereby the members of
$M$
are copied into$C$
. Perhaps we could say that every member of a mixin is transformed into a top level function with a fresh name (not private), and$C$
contains methods whose body is just a forwarding call to such a top-level function. This will not address all issues, however, because it is still a problem that private mixin methods would be reinterpreted as private-in-$L_C$
.The text was updated successfully, but these errors were encountered: