Files
sdk/tests/language/string/interpolation_and_buffer_legacy_test.dart
T
Robert Nystrom 1b2454b85e Migrate language_2/string to null safety.
Change-Id: Ib09f268c8a8edffba007cdd4962550a5e78ff808
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151090
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2020-06-17 21:14:43 +00:00

27 lines
1003 B
Dart

// 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.
// A null safe library cannot implement `toString()` and return `null`, but a
// legacy library, which may be called from null safe code, can. Test that that
// doesn't fail.
// Requirements=nnbd-weak
import "package:expect/expect.dart";
import "interpolation_and_buffer_legacy_lib.dart";
void main() {
var n = ToStringNull();
// Throws immediately when evaluating the first interpolated expression.
Expect.throws<Error>(() => "$n${throw "unreachable"}");
// Throws immediately when adding object that doesn't return a String.
Expect.throws<Error>(
() => StringBuffer()..write(n)..write(throw "unreachable"));
// Same behavior for constructor argument as if adding it to buffer later.
Expect.throws<Error>(() => StringBuffer(n)..write(throw "unreachable"));
}