// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // @dart=2.9 /*@testedFeatures=inference*/ library test; void block_test() { List Function() g; g = /*@ returnType=List* */ () { return /*@ typeArgs=Object* */ [3]; }; assert(g is List Function()); assert(g is! List Function()); g(). /*@target=List.add*/ add("hello"); // No runtime error List l = /*@ typeArgs=int* */ [3]; g = /*@ returnType=List* */ () { return l; }; assert(g is List Function()); assert(g is List Function()); try { g(). /*@target=List.add*/ add("hello"); // runtime error throw 'expected a runtime error'; } on TypeError {} Object o = l; g = /*@ returnType=List* */ () { return o; }; // No implicit downcast on the assignment, implicit downcast on the return assert(g is List Function()); assert(g is! List Function()); assert(g is! Object Function()); g(); // No runtime error; o = 3; try { g(); // Failed runtime cast on the return type of f throw 'expected a runtime error'; } on TypeError {} } void arrow_test() { List Function() g; g = /*@ returnType=List* */ () => /*@ typeArgs=Object* */ [3]; assert(g is List Function()); assert(g is! List Function()); g(). /*@target=List.add*/ add("hello"); // No runtime error List l = /*@ typeArgs=int* */ [3]; g = /*@ returnType=List* */ () => l; assert(g is List Function()); assert(g is List Function()); try { g(). /*@target=List.add*/ add("hello"); // runtime error throw 'expected a runtime error'; } on TypeError {} Object o = l; g = /*@ returnType=List* */ () => o; // No implicit downcast on the assignment, implicit downcast on the return assert(g is List Function()); assert(g is! List Function()); assert(g is! Object Function()); g(); // No runtime error; o = 3; try { g(); // Failed runtime cast on the return type of f throw 'expected a runtime error'; } on TypeError {} } main() { block_test(); arrow_test(); }