// Copyright (c) 2020, 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. // Test for null assertions for parameters in NNBD weak mode. // Requirements=nnbd-weak // VMOptions=--enable-asserts // dart2jsOptions=--enable-asserts -DcheckString=false // SharedOptions=--null-assertions // Opt out of Null Safety: // @dart = 2.6 import "package:expect/expect.dart"; import 'parameter_checks_opted_in.dart'; bool Function(Object) asserted(String name) { if (const bool.fromEnvironment('checkString', defaultValue: true)) { return (e) => e is AssertionError && e.toString().contains("$name != null"); } else { return (e) => e is AssertionError; } } main() { Expect.throws(() { foo1(null); }, asserted("a")); Expect.throws(() { foo2(1, null); }, asserted("b")); Expect.throws(() { foo3(); }, asserted("b")); Expect.throws(() { foo3(b: null); }, asserted("b")); foo4a(null); Expect.throws(() { foo4b(null); }, asserted("a")); foo5a(null); Expect.throws(() { foo5b(null); }, asserted("a")); foo6a(null); Expect.throws(() { foo6b(null); }, asserted("a")); Expect.throws(() { bar().call(null); }, asserted("x")); }