-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Crash with invalid named mixin application #48919
Comments
Similar code causes a crash in the analyzer
Which raises a question - does the parser know whether it is a function type or a named type? If it does, it would be nice to report an error and recover. |
And similar issue with
|
...and for
|
@johnniwinther why was I assigned to this? I initially thought it was some sort of parsing error, but the parser seems to conform to the spec to me, e.g.
As I read it all of these should be OK:
|
This sounds like this is an issue in both the CFE and analyzer. Reassigning. |
@eernstg Is this correct? Do we allow function types as superclasses? Just syntactically or also semantically? It looks that |
It is definitely intended that a function type as a superclass should be a compile-time error. The change which was made in order to ensure that it has no effect if a class The PR where null safety is integrated into the language specification is ongoing work (a snippet of it is available at dart-lang/language#2023), but it contains a short section defining 'class building types'. That section corrects a couple of mistakes and updates the definitions to take null safety into account, because it specifies that The concept of being a class building type is then used in the sections about This means that function types aren't mentioned today, but that's clearly a mistake, and it is being corrected when the null safety updates are landed (reviews are ongoing, we will get there ;-). |
The function types are given an empty name in that case. Those types are further discarded and can have any intermediary name. Part of #48919 Change-Id: I57d223ee7914d0227baa3a4ef5733bb8055fa2c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244240 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
The fix for the CFE has landed: https://dart-review.googlesource.com/c/sdk/+/244240. |
If this is a compile-time error to use a function type as a superclass, then should the parser report this error instead? When we see that this is an explicit function type, not a type alias, of course. |
The grammar currently includes the following:
While it would make sense to me for the grammar to exclude function types in the extends clause (@eernstg), it currently doesn't. Because the grammar allows it, IMO it shouldn't be a parse error. |
My understanding was that it is an oversight that the grammar does not exclude function types. And because we know this, it does not seem right to hold to the letter of the current grammar and insist that CFE and analyzer should do their own error reporting for invalid syntax here. I did this initially in the analyzer, but thought that it might be beneficial to check syntax in one place - in the parser. |
I think it would be complicating matters (slightly) for no good reason if we were to make it a syntax error: As @scheglov mentioned, it would still be possible to use a function type as a superinterface via a type alias, so we would still have to check syntactic forms that aren't a So unless there are grammatical reasons for doing it (parser speed? disambiguation?), I think we shouldn't build double-walls against dangers when one wall will do just fine. ;-) |
I saw this issue on emacs so I had reported it on the lsp project: emacs-lsp/lsp-dart#191 Just declaring a |
Maybe this is related: The Dart compiler doesn't seem to auto-cast this: mixin Foo {
void bar();
}
class FooFunction with Foo {
void call() {}
void bar() {}
}
main() {
Function() fun = FooFunction();
if (fun is Foo) {
fun.bar();
}
} Fails with:
An explicit cast is needed: if (fun is Foo) {
(fun as Foo).bar();
} So there's something funky about functions and mixins?! |
I see from
dart
run:The text was updated successfully, but these errors were encountered: