mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 22:11:19 +00:00
c74dd07a4a
Using interpolation ensures that a `null` returned from `o.toString()` in a non-sound application is treated consistently. The error message has been upgraded to include the receiver to make it easier to find the method. Since this error values are reported using `Error.safeToString`, this will be reported using the class name: ``` ArgumentError (object): toString method returned 'null': Instance of 'BadToString' ``` VM, DDC and dart2js runtimes are updated to make the handling consistent on VM and web. TEST=added Change-Id: I48d8f721dfb3a431dbeacdaa39a9f3a8273e902c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214741 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
31 lines
727 B
Dart
31 lines
727 B
Dart
// Copyright (c) 2021, 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
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class BadToString {
|
|
@override
|
|
String toString() => null;
|
|
}
|
|
|
|
void test(expected, object) {
|
|
var message = '';
|
|
if (expected == null) {
|
|
Expect.throws(() => '$object',
|
|
(error) => '$error'.contains("toString method returned 'null'"));
|
|
} else {
|
|
Expect.equals(expected, '$object');
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
test("123", 123);
|
|
test("null", null);
|
|
test(null, BadToString());
|
|
test(null, [BadToString()]);
|
|
test(null, {BadToString()});
|
|
}
|