Skip to content

Analyzer soundness problem: Return void to Null allowed. #42093

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

Closed
eernstg opened this issue May 28, 2020 · 1 comment
Closed

Analyzer soundness problem: Return void to Null allowed. #42093

eernstg opened this issue May 28, 2020 · 1 comment
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. NNBD Issues related to NNBD Release soundness type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented May 28, 2020

Consider the following program:

void v = "Hello";

Null test() {
  return v;
}

void main() {
  int? i = test();
  if (i != null) {
    i.isEven;
  }
}

The analyzer (2.9.0-11.0.dev and 2eaac80) accepts this program with no errors, but it is not sound to allow an expression of type void to be returned when the return type is Null, because the returned object could have any type whatsoever.

A similar issue arises with the asynchronous form:

import 'dart:async';

void v = "Hello";

Future<Null> test() async {
  return v;
}

void main() async {
  int? i = await test();
  if (i != null) {
    i.isEven;
  }
}
@eernstg eernstg added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) soundness labels May 28, 2020
@eernstg eernstg added the NNBD Issues related to NNBD Release label May 28, 2020
@scheglov scheglov self-assigned this May 30, 2020
@scheglov
Copy link
Contributor

I believe that the issue was fixed by implementing changes requested in #41803.

I added a new test in https://dart-review.googlesource.com/c/sdk/+/149604.

dart-bot pushed a commit that referenced this issue Jun 1, 2020
[email protected]

Bug: #42093
Change-Id: I96b5c1597d7d16b269b6f6c7d3fd67bd960ff589
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149604
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. NNBD Issues related to NNBD Release soundness type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants