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

alwaysThrows should silence missing return hints #31384

Closed
nex3 opened this issue Nov 16, 2017 · 2 comments
Closed

alwaysThrows should silence missing return hints #31384

nex3 opened this issue Nov 16, 2017 · 2 comments
Assignees
Labels
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)

Comments

@nex3
Copy link
Member

nex3 commented Nov 16, 2017

When I run the analyzer (2.0.0-dev.7) on the following code:

import 'package:meta/meta.dart';

int foo(bool yes) {
  if (yes) return 1;
  error("no");
}

@alwaysThrows
void error(String message) {
  throw message;
}

I get this message:

hint • This function declares a return type of 'int', but doesn't end with a return statement at test.dart:3:1 • missing_return   

Because the analyzer knows that error() always throws, I'd expect it to be able to deduce that no return is needed, just like it does if I manually write throw "no".

@nex3 nex3 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 Nov 16, 2017
@nex3
Copy link
Member Author

nex3 commented Nov 16, 2017

cc @srawlins, who added @alwaysThrows in c6d6a69.

@srawlins srawlins self-assigned this Dec 6, 2017
whesse pushed a commit that referenced this issue Dec 7, 2017
The meta package version 1.1.0 includes a new `alwaysThrows`, which developers
can use to annotate methods that always throw. This helps to avoid erroneous
DEAD_CODE warnings from analyzer.

Bug: #31384
Change-Id: I70e2469b4f3a0d2c87064851160b268ea2259807
Reviewed-on: https://dart-review.googlesource.com/26563
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
@srawlins
Copy link
Member

Fixed with 0a62533.

kevmoo added a commit to dart-lang/pub that referenced this issue Dec 16, 2017
nex3 pushed a commit to dart-lang/pub that referenced this issue Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

2 participants