dart-sdk/tests/corelib/string_operations_with_null_test.dart
Alexander Markov e0b7841d16 [vm/nnbd] Fix CompileType::IsAssignableTo for nullable types in strong mode
Also, tests/corelib/string_operations_with_null_test.dart is fixed for
strong mode: in strong mode TypeError is thrown when null is casted
to a non-nullable type; in weak mode null is silently passed and
ArgumentError or NoSuchMethodError is thrown.

Change-Id: I566a80293ffb03752cc3409e1b79491f0aff6888
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140779
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-03-25 17:32:02 +00:00

19 lines
664 B
Dart

// Copyright (c) 2013, 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.
import "package:expect/expect.dart";
@pragma('dart2js:noInline')
@pragma('dart2js:assumeDynamic')
returnStringOrNull() {
return new DateTime.now().millisecondsSinceEpoch == 0 ? 'foo' : null;
}
main() {
Expect.throws(() => 'foo' + returnStringOrNull(),
(e) => e is ArgumentError || e is TypeError);
Expect.throws(() => 'foo'.split(returnStringOrNull()),
(e) => e is ArgumentError || e is NoSuchMethodError || e is TypeError);
}