Skip to content
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

Dart does not throw error if function argument parameter extends Null #33701

Closed
iarkh opened this issue Jun 29, 2018 · 5 comments
Closed

Dart does not throw error if function argument parameter extends Null #33701

iarkh opened this issue Jun 29, 2018 · 5 comments
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@iarkh
Copy link
Contributor

iarkh commented Jun 29, 2018

Dart SDK Version: 2.0.0-dev.55.0
OS: Windows 10

Sample code below declares a [typedef] with parameter which extends [Null]. It causes a lot of compiler errors with dartanalyzer and passes without errors with dart.

typedef F<X extends Null> = Function(X);
main() {}

This is similar to the issue #33699, however analyzer produces different errors in these two cases, so we would be better to have separate issues.

I believe both tools should behave in the same way.
Dartanalyzer sample output is:

Analyzing typedef_ret_extends_neg_l1_t05.dart...
  error - 'X' can't be a supertype of its upper bound at typedef_ret_extends_neg_l1_t05.dart:50:11 - type_parameter_supertype_of_its_bound
1 error found.

Dart stdout and stderr are empty, no exceptions or warnings there.

@iarkh iarkh changed the title Dart does not throw error if function argument extends Null Dart does not throw error if function argument parameter extends Null Jun 29, 2018
@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 29, 2018
@lrhn
Copy link
Member

lrhn commented Jun 29, 2018

The error seems spurious.

There is nothing inherently problematic with allowing Null as a type parameter bound (apart from the class being useless, so it's also not a big loss if we don't).

If we have a rule preventing a type parameter from being a supertype of its bound, the phrasing needs to be fixed so it doesn't allow this any more than it disallows <X extends Object>.

@iarkh
Copy link
Contributor Author

iarkh commented Jun 29, 2018

OK, but if Null is allowed, analyzer should not throw error too.
Should I update synopsys accordingly?

@eernstg
Copy link
Member

eernstg commented Jun 29, 2018

We could simply accept the current wording including the error with an explicitly Null bound, noting that it is really not a useful case anyway.

In order to ensure that this issue can stay focused on its original purpose, I've created a new issue #33709 addressing the language question. Marking this issue as blocked: Waiting for #33709.

@eernstg eernstg added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). area-front-end Use area-front-end for front end / CFE / kernel format related issues. status-blocked Blocked from making progress by another (referenced) issue and removed type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). status-blocked Blocked from making progress by another (referenced) issue labels Jun 29, 2018
@eernstg
Copy link
Member

eernstg commented Jul 3, 2018

Removing blocked status: As of 4fd0404, the subtype circularity prevention rule in the language specification has be adjusted such that Null is now an acceptable upper bound for a type variable. The front end does not report an error, which is ok, but the analyzer should now be updated to accept the example program.

So we need to change the area back to analyzer—done.

@eernstg eernstg added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. and removed area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Jul 3, 2018
@bwilkerson bwilkerson added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Aug 28, 2018
@bwilkerson bwilkerson added this to the Dart2.1 milestone Aug 28, 2018
@devoncarew devoncarew modified the milestones: Dart2.1, PostDart2.1 Sep 5, 2018
@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
@srawlins srawlins added the analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 17, 2020
@srawlins
Copy link
Member

Analyzer no longer reports an error for this code (both with and without null-safety).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants