Skip to content

Commit bc0d3e2

Browse files
authored
Fix problems with head analyzer (#2680)
* fix? * dartfmt * rebuild with override
1 parent 45d7e76 commit bc0d3e2

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ class _Renderer_Accessor extends RendererBase<Accessor> {
3333
CT_,
3434
() => {
3535
..._Renderer_ModelElement.propertyMap<CT_>(),
36+
'characterLocation': Property(
37+
getValue: (CT_ c) => c.characterLocation,
38+
renderVariable: (CT_ c, Property<CT_> self,
39+
List<String> remainingNames) =>
40+
self.renderSimpleVariable(
41+
c, remainingNames, 'CharacterLocation'),
42+
isNullValue: (CT_ c) => c.characterLocation == null,
43+
renderValue:
44+
(CT_ c, RendererBase<CT_> r, List<MustachioNode> ast) {
45+
return renderSimple(c.characterLocation, ast, r.template,
46+
parent: r,
47+
getters: _invisibleGetters['CharacterLocation']);
48+
},
49+
),
3650
'definingCombo': Property(
3751
getValue: (CT_ c) => c.definingCombo,
3852
renderVariable:

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: 7 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 = set_literals.constants
407+
.firstWhere((v) => v.name == 'untypedMapWithoutConst');
405408
typedSet = set_literals.constants.firstWhere((v) => v.name == 'typedSet');
406409
});
407410

@@ -431,6 +434,10 @@ 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(
440+
untypedMapWithoutConst.constantValue, matches(RegExp('(const )?{}')));
434441
expect(untypedMap.modelType.name, equals('Map'));
435442
expect(
436443
(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)