New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear definition of self-referencing typedef #9592
Comments
Yes it is. The wording does need work, especially given all the other changes that have occurred since it was put in place. Added Accepted label. |
That is disturbing. Since we use structural equality on function types, such a typedef introduces a recursive type which is just as difficult to handle as the invalid 'typedef F F()'. For instance the typedefs typedef F(List<F> list); define the same function type and F foo(G g) => g; should therefore be valid in checked mode. Worse is that we can make even more complex structures like typedef H(List<I> list); all of which are equivalent to F and G. |
Note that the VM currently crashes on recursive types (http://dartbug.com/9611). Dart2js fails gracefully by just ignoring the structure of typedefs, currently. I think that we should restrict typedefs to avoid recursive types completely. This means that all of the following typedefs are illegal: typedef A1 A1(); // Cyclic through return type. typedef void A(B b); // Cyclic through another typedef. typedef void C(D d); // Cyclic through more typedefs. typedef F<T extends F>(T t); // Cyclic through type variable bound. |
All of the cases listed the above works now (produce compile-time erorrs). Tested on Dart VM version: 1.14.0-dev.1.0 (Wed Nov 18 18:17:16 2015) on "windows_x64" |
typedef F1<F1>(F1 f);
typedef F2<F2>([F2 f]);
typedef F3<F3>({F3 f}); The code above doesn't produce compile errors. I believe that it's according the spec but... Does it makes sense to allow typedefs like those above? |
typedef F1<F1>(F1 f);
typedef F2<F2>([F2 f]);
typedef F3<F3>({F3 f}); These are OK, though confusing. They are declaring type parameters that shadow the name of the typedef itself. Looks like the spec wording was tweaking and the implementations are doing the right thing, so I'm going to close this. |
According to §15.3 it is 'a compile-time error if a typedef refers to itself via a chain of references that does not include a class declaration.'
What 'include' means in this context is unclear. For instance, is this a valid typedef?
typedef F(List<F> list);
The text was updated successfully, but these errors were encountered: