Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 3827325

Browse files
committed
Allow some fields to be overridden in strong mode.
For consistency, any field in a class that's meant to be extended can be overridden. [email protected], [email protected] Review URL: https://codereview.chromium.org//1728113002 .
1 parent 32de304 commit 3827325

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.2.2
2+
3+
* Allow `SourceSpanException.message`, `SourceSpanFormatException.source`, and
4+
`SourceSpanWithContext.context` to be overridden in strong mode.
5+
16
# 1.2.1
27

38
* Fix the declared type of `FileSpan.start` and `FileSpan.end`. In 1.2.0 these

lib/src/span_exception.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import 'span.dart';
66

77
/// A class for exceptions that have source span information attached.
88
class SourceSpanException implements Exception {
9+
// This is a getter so that subclasses can override it.
910
/// A message describing the exception.
10-
final String message;
11+
String get message => _message;
12+
final String _message;
1113

14+
// This is a getter so that subclasses can override it.
1215
/// The span associated with this exception.
1316
///
1417
/// This may be `null` if the source location can't be determined.
15-
final SourceSpan span;
18+
SourceSpan get span => _span;
19+
final SourceSpan _span;
1620

17-
SourceSpanException(this.message, this.span);
21+
SourceSpanException(this._message, this._span);
1822

1923
/// Returns a string representation of [this].
2024
///
@@ -32,10 +36,9 @@ class SourceSpanException implements Exception {
3236
/// A [SourceSpanException] that's also a [FormatException].
3337
class SourceSpanFormatException extends SourceSpanException
3438
implements FormatException {
35-
final _source;
36-
37-
// Subclasses may narrow the type.
39+
// This is a getter so that subclasses can override it.
3840
dynamic get source => _source;
41+
final _source;
3942

4043
int get offset => span == null ? null : span.start.offset;
4144

lib/src/span_with_context.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import 'utils.dart';
88

99
/// A class that describes a segment of source text with additional context.
1010
class SourceSpanWithContext extends SourceSpanBase {
11+
// This is a getter so that subclasses can override it.
1112
/// Text around the span, which includes the line containing this span.
12-
final String context;
13+
String get context => _context;
14+
final String _context;
1315

1416
/// Creates a new span from [start] to [end] (exclusive) containing [text], in
1517
/// the given [context].
@@ -20,7 +22,7 @@ class SourceSpanWithContext extends SourceSpanBase {
2022
/// [text] should start at `start.column` from the beginning of a line in
2123
/// [context].
2224
SourceSpanWithContext(
23-
SourceLocation start, SourceLocation end, String text, this.context)
25+
SourceLocation start, SourceLocation end, String text, this._context)
2426
: super(start, end, text) {
2527
if (!context.contains(text)) {
2628
throw new ArgumentError(

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_span
2-
version: 1.2.1
2+
version: 1.2.2
33
author: Dart Team <[email protected]>
44
description: A library for identifying source spans and locations.
55
homepage: https://github.com/dart-lang/source_span

0 commit comments

Comments
 (0)