stringify method

String stringify(
  1. Object? value
)

Implementation

String stringify(Object? value) {
  if (value == null) return 'null';
  if (value is bool) return value.toString();
  // The three interpreted values that can carry a script `toString` override.
  //
  // SCE116 added the second and third. Without them an enum value or an
  // extension-type instance would still render correctly — `toString()` on
  // those types dispatches too — but through the HOST-facing path, which
  // degrades instead of throwing. Interpolation inside a script must keep
  // Dart's semantics, so it calls the strict form here; see
  // [renderInterpretedToString] for the split and why it exists.
  final InterpretedFunction? override = switch (value) {
    InterpretedInstance() => value.klass.findInstanceMethod('toString'),
    InterpretedEnumValue() => value.parentEnum.findInstanceMethod('toString'),
    InterpretedExtensionTypeInstance() =>
      value.extensionType.methods['toString'],
    _ => null,
  };
  if (override != null) {
    final result = callInterpretedToString(
      override,
      value as RuntimeValue,
      this,
    );
    if (result is String) return result;
    if (result == null) return 'null';
    return result.toString();
  }
  return value.toString();
}