source_span icon indicating copy to clipboard operation
source_span copied to clipboard

Consider not using runtimeType

Open jonasfj opened this issue 3 years ago • 2 comments
trafficstars

This causes code-size warnings when compiling to js:

Hint: Using '.runtimeType.toString()' causes the compiler to generate more code because it needs to preserve type arguments on generic classes, even if they are not necessary elsewhere. If used only for debugging, consider using option --lax-runtime-type-to-string to reduce the code size impact.

And we only use it in:

https://github.com/dart-lang/source_span/blob/24151fd80e4557a626f81f2bc0d6a2ebde172cae/lib/src/span_mixin.dart#L82-L83

Maybe we can just change it to:

String toString() => '<SourceSpan: from $start to $end "$text">';

And have subclasses overwrite toString to ensure that they keep their name.

jonasfj avatar Jun 10 '22 08:06 jonasfj

This sounds reasonable to me; I doubt it's critical that the toString() method identify the exact subclass of the sourcespan.

devoncarew avatar Jun 10 '22 18:06 devoncarew

For posterity, the lint we want to enable to catch violations here is no_runtimeType_toString (that lint does have an issue where it doesn't report all violations: https://github.com/dart-lang/linter/issues/3635).

devoncarew avatar Sep 02 '22 20:09 devoncarew