Skip to content

Commit 5a6137d

Browse files
committed
fix?
1 parent 45d7e76 commit 5a6137d

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

lib/src/model/accessor.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class Accessor extends ModelElement implements EnclosedElement {
2121
[ExecutableMember /*?*/ originalMember])
2222
: super(element, library, packageGraph, originalMember);
2323

24+
@override
25+
CharacterLocation get characterLocation {
26+
if (element.nameOffset < 0) {
27+
assert(element.isSynthetic, 'Invalid offset for non-synthetic element');
28+
// TODO(jcollins-g): switch to [element.nonSynthetic] after analyzer 1.8
29+
return enclosingCombo.characterLocation;
30+
}
31+
return super.characterLocation;
32+
}
33+
2434
@override
2535
PropertyAccessorElement get element => super.element;
2636

test/end2end/model_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ void main() {
389389
inferredTypeSet,
390390
specifiedSet,
391391
untypedMap,
392+
untypedMapWithoutConst,
392393
typedSet;
393394

394395
setUpAll(() async {
@@ -402,6 +403,8 @@ void main() {
402403
set_literals.constants.firstWhere((v) => v.name == 'specifiedSet');
403404
untypedMap =
404405
set_literals.constants.firstWhere((v) => v.name == 'untypedMap');
406+
untypedMapWithoutConst =
407+
set_literals.constants.firstWhere((v) => v.name == 'untypedMapWithoutConst');
405408
typedSet = set_literals.constants.firstWhere((v) => v.name == 'typedSet');
406409
});
407410

@@ -431,6 +434,9 @@ void main() {
431434
.toList(),
432435
equals(['int']));
433436
expect(specifiedSet.constantValue, equals('const {}'));
437+
// The analyzer is allowed to return a string with or without leading
438+
// `const` here.
439+
expect(untypedMapWithoutConst.constantValue, matches(RegExp('(const )?{}')));
434440
expect(untypedMap.modelType.name, equals('Map'));
435441
expect(
436442
(untypedMap.modelType as ParameterizedElementType)

testing/test_package/lib/example.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class aThingToDo {
5858
const aThingToDo(this.who, this.what);
5959
}
6060

61-
const ConstantCat MY_CAT = ConstantCat('tabby');
62-
const List<String> PRETTY_COLORS = <String>[COLOR_GREEN, COLOR_ORANGE, 'blue'];
61+
const ConstantCat MY_CAT = const ConstantCat('tabby');
62+
const List<String> PRETTY_COLORS = const <String>[COLOR_GREEN, COLOR_ORANGE, 'blue'];
6363
@deprecated
6464
int deprecatedField;
6565

@@ -313,7 +313,7 @@ class Dog implements Cat, E {
313313
static const String aStaticConstField = "A Constant Dog";
314314

315315
/// Verify link substitution in constants (#1535)
316-
static const ShortName aName = ExtendedShortName("hello there");
316+
static const ShortName aName = const ExtendedShortName("hello there");
317317

318318
@protected
319319
final int aProtectedFinalField = 84;

testing/test_package/lib/fake.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class AClassWithFancyProperties {
254254
String aProperty;
255255
}
256256

257-
const _APrivateConstClass CUSTOM_CLASS_PRIVATE = _APrivateConstClass();
257+
const _APrivateConstClass CUSTOM_CLASS_PRIVATE = const _APrivateConstClass();
258258

259259
/// Type inference mixing with anonymous functions.
260260
final importantComputations = {
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// @dart=2.9
22

3-
const inferredTypeSet = {1, 3, 5};
4-
const Set<int> specifiedSet = {};
5-
const untypedMap = {};
6-
const typedSet = <String>{};
3+
const inferredTypeSet = const {1, 3, 5};
4+
const Set<int> specifiedSet = const {};
5+
const untypedMap = const {};
6+
const typedSet = const <String>{};
7+
const untypedMapWithoutConst = {};
8+
79

810
class AClassContainingLiterals {
911
final int value1;
@@ -12,4 +14,4 @@ class AClassContainingLiterals {
1214
const AClassContainingLiterals(this.value1, this.value2);
1315
}
1416

15-
const aComplexSet = {AClassContainingLiterals(3, 5)};
17+
const aComplexSet = const {const AClassContainingLiterals(3, 5)};

0 commit comments

Comments
 (0)