Synthetic fields are not final.
They don't have the `final` modifier (or `const`).
They might be not writable because they don't have a setter.
Change-Id: I1d344e187bc63bac8167ff6cf708b1d2a8fb418a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201780
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
index 5dcfc27..8c58caf 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
@@ -998,7 +998,6 @@
property = existing;
} else {
var field = TopLevelVariableElementImpl(name, -1);
- field.isFinal = true;
property = field;
}
} else {
@@ -1007,7 +1006,6 @@
property = existing;
} else {
var field = FieldElementImpl(name, -1);
- field.isFinal = true;
field.isStatic = accessor.isStatic;
property = field;
}
diff --git a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
index cfd22eb..2761da8 100644
--- a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
+++ b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart
@@ -1033,7 +1033,6 @@
bool isStatic = false,
}) {
var field = FieldElementImpl(name, -1);
- field.isFinal = true;
field.isStatic = isStatic;
field.isSynthetic = true;
field.type = type;
diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart
index bd68a35..af2043f 100644
--- a/pkg/analyzer/test/src/summary/element_text.dart
+++ b/pkg/analyzer/test/src/summary/element_text.dart
@@ -997,6 +997,7 @@
} else {
writeDocumentation(e);
writeMetadata(e, '', '\n');
+ writeIf(e.isSynthetic, 'synthetic ');
writeIf(e is TopLevelVariableElementImpl && e.isExternal, 'external ');
}
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 2a6edcb..bd6e007 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -1149,11 +1149,15 @@
test_class_getter_static() async {
var library = await checkLibrary('class C { static int get x => null; }');
- checkElementText(library, r'''
+ checkElementText(
+ library,
+ r'''
class C {
+ synthetic static int x;
static int get x {}
}
-''');
+''',
+ withSyntheticFields: true);
}
test_class_getters() async {
@@ -1174,12 +1178,16 @@
void set x(int value) {}
}
''');
- checkElementText(library, r'''
+ checkElementText(
+ library,
+ r'''
class C {
+ synthetic int x;
int get x {}
void set x(int value) {}
}
-''');
+''',
+ withSyntheticFields: true);
}
test_class_implicitField_setterFirst() async {
@@ -1189,12 +1197,16 @@
int get x => 0;
}
''');
- checkElementText(library, r'''
+ checkElementText(
+ library,
+ r'''
class C {
+ synthetic int x;
void set x(int value) {}
int get x {}
}
-''');
+''',
+ withSyntheticFields: true);
}
test_class_interfaces() async {
@@ -14773,6 +14785,36 @@
''');
}
+ test_unit_implicitVariable_getterFirst() async {
+ var library = await checkLibrary('''
+int get x => 0;
+void set x(int value) {}
+''');
+ checkElementText(
+ library,
+ r'''
+synthetic int x;
+int get x {}
+void set x(int value) {}
+''',
+ withSyntheticFields: true);
+ }
+
+ test_unit_implicitVariable_setterFirst() async {
+ var library = await checkLibrary('''
+void set x(int value) {}
+int get x => 0;
+''');
+ checkElementText(
+ library,
+ r'''
+synthetic int x;
+void set x(int value) {}
+int get x {}
+''',
+ withSyntheticFields: true);
+ }
+
test_unit_variable_final_withSetter() async {
var library = await checkLibrary(r'''
final int foo = 0;
@@ -15167,7 +15209,7 @@
as PropertyAccessorElementImpl;
var variable = getter.variable as TopLevelVariableElementImpl;
expect(variable, isNotNull);
- expect(variable.isFinal, isTrue);
+ expect(variable.isFinal, isFalse);
expect(variable.getter, same(getter));
expect('${variable.type}', 'int');
expect(variable, same(_elementOfDefiningUnit(library, ['@variable', 'x'])));
diff --git a/pkg/analyzer/test/src/summary/top_level_inference_test.dart b/pkg/analyzer/test/src/summary/top_level_inference_test.dart
index 906d2c1..b778258 100644
--- a/pkg/analyzer/test/src/summary/top_level_inference_test.dart
+++ b/pkg/analyzer/test/src/summary/top_level_inference_test.dart
@@ -1514,7 +1514,7 @@
}
class B implements A {
int x;
- synthetic final int y;
+ synthetic int y;
synthetic int z;
int get y {}
void set z(int _) {}
@@ -1565,7 +1565,7 @@
}
class B<T> implements A<T> {
T x;
- synthetic final T y;
+ synthetic T y;
synthetic T z;
T get y {}
void set z(T _) {}
@@ -1816,7 +1816,7 @@
library,
r'''
abstract class A {
- synthetic final int x;
+ synthetic int x;
int get x;
}
abstract class B {
@@ -1824,7 +1824,7 @@
void set x(String _);
}
class C implements A, B {
- synthetic final int x;
+ synthetic int x;
int get x {}
}
''',
@@ -1848,7 +1848,7 @@
library,
r'''
abstract class A {
- synthetic final int x;
+ synthetic int x;
int get x;
}
abstract class B {
@@ -1904,7 +1904,7 @@
library,
r'''
abstract class A {
- synthetic final int x;
+ synthetic int x;
int get x;
}
abstract class B {
@@ -1912,7 +1912,7 @@
void set x(int _);
}
class C implements A, B {
- synthetic final int x;
+ synthetic int x;
int get x {}
}
''',
@@ -1935,7 +1935,7 @@
library,
r'''
abstract class A {
- synthetic final int x;
+ synthetic int x;
int get x;
}
abstract class B {