Skip to content

Commit ef04f5d

Browse files
DanTupCommit Queue
authored andcommitted
[analyzer] Update Name.forSetter to only add trailing = if not already there
Change-Id: Id6d98a9a2902539635d2cb5acd23d3ddd4832d5d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391442 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent c3ce683 commit ef04f5d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,11 @@ class Name {
13141314
}
13151315

13161316
Name get forSetter {
1317-
return Name(libraryUri, '$name=');
1317+
if (name.endsWith('=')) {
1318+
return this;
1319+
} else {
1320+
return Name(libraryUri, '$name=');
1321+
}
13181322
}
13191323

13201324
@override

pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ main() {
2525
defineReflectiveTests(InheritanceManager3Test);
2626
defineReflectiveTests(InheritanceManager3Test_elements);
2727
defineReflectiveTests(InheritanceManager3Test_ExtensionType);
28+
defineReflectiveTests(InheritanceManager3NameTest);
2829
defineReflectiveTests(UpdateNodeTextExpectations);
2930
});
3031
}
@@ -1413,6 +1414,47 @@ class B extends A {
14131414
}
14141415
}
14151416

1417+
@reflectiveTest
1418+
class InheritanceManager3NameTest {
1419+
test_equals() {
1420+
expect(Name(null, 'foo'), Name(null, 'foo'));
1421+
expect(Name(null, 'foo'), Name(null, 'foo=').forGetter);
1422+
expect(Name(null, 'foo='), Name(null, 'foo='));
1423+
expect(Name(null, 'foo='), Name(null, 'foo').forSetter);
1424+
expect(Name(null, 'foo='), Name(null, 'foo').forSetter.forSetter.forSetter);
1425+
}
1426+
1427+
test_forGetter() {
1428+
var name = Name(null, 'foo');
1429+
expect(name.forGetter.name, 'foo');
1430+
expect(name, name.forGetter);
1431+
}
1432+
1433+
test_forGetter_fromSetter() {
1434+
var name = Name(null, 'foo=');
1435+
expect(name.forGetter.name, 'foo');
1436+
}
1437+
1438+
test_forSetter() {
1439+
var name = Name(null, 'foo=');
1440+
expect(name.forSetter.name, 'foo=');
1441+
expect(name, name.forSetter);
1442+
}
1443+
1444+
test_forSetter_fromGetter() {
1445+
var name = Name(null, 'foo');
1446+
expect(name.forSetter.name, 'foo=');
1447+
}
1448+
1449+
test_name_getter() {
1450+
expect(Name(null, 'foo').name, 'foo');
1451+
}
1452+
1453+
test_name_setter() {
1454+
expect(Name(null, 'foo=').name, 'foo=');
1455+
}
1456+
}
1457+
14161458
@reflectiveTest
14171459
class InheritanceManager3Test extends _InheritanceManager3Base {
14181460
test_getInherited_closestSuper() async {

0 commit comments

Comments
 (0)