Skip to content

dart2 analyser does not report an error #33847

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
ngolovleva opened this issue Jul 13, 2018 · 1 comment
Closed

dart2 analyser does not report an error #33847

ngolovleva opened this issue Jul 13, 2018 · 1 comment
Labels
closed-as-intended Closed as the reported issue is expected behavior

Comments

@ngolovleva
Copy link

Dart analyzer does not report an error when a function with one parameter is invoked and the type of an actual argument is not a subtype of a formal argument type. Generated code reports a run-time exception type 'S0' is not a subtype of type 'Future'.

import "dart:async";

class S0 {}
FutureOr<S0> t0Instance = new S0();
// S0 is not a subtype of Future<S0>
Future<S0> t1Instance = new Future<S0>.value(new S0());
f1(Future<S0> t1) {}

main() {
  f1(t0Instance);     // <- exception
}

dart test.dart
Unhandled exception:
type 'S0' is not a subtype of type 'Future'
#0 main (file:///home/ngl/dart_wd/dtests/co19/LanguageFeatures/Subtyping/static/generated/ztest1.dart:10:6)
#1 _startIsolate. (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

Tested with Dart VM version: 2.0.0-dev.68.0 (Tue Jul 10 14:47:26 2018 +0200) on "linux_x64"

@matanlurey matanlurey added the closed-as-intended Closed as the reported issue is expected behavior label Jul 13, 2018
@matanlurey
Copy link
Contributor

This is an implicit downcast, a feature of Dart2.

Because FutureOr<S0> could be a Future<S0>, it is allowed and checked at runtime.

Issue #31410 is tracking removing and augmenting this in future versions of Dart/the analyzer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants