Set default value for fixed-size array fields
Using empty list as a special value was a workaround to set an explicit
value for fixed-size array fields.
Instead, we'd better be explicit about "default value" for parcelable
fields because it applies to other types as well (e.g. enum,
ParcelableHolder)
Bug: 207087196
Test: tests/golden_test.sh check
Change-Id: Ie133fff3f801eb3276e91f6b87539ede495bda9f
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 14afa12..244ec4b 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -334,12 +334,6 @@
AidlConstantValue* AidlConstantValue::Default(const AidlTypeSpecifier& specifier) {
AidlLocation location = specifier.GetLocation();
- // Initialize non-nullable fixed-size arrays with {}("empty list").
- // Each backend will handle it differently. For example, in Rust, it can be mapped to
- // "Default::default()".
- if (specifier.IsFixedSizeArray() && !specifier.IsNullable()) {
- return Array(location, std::make_unique<std::vector<std::unique_ptr<AidlConstantValue>>>());
- }
// allocation of int[0] is a bit wasteful in Java
if (specifier.IsArray()) {
return nullptr;
@@ -596,7 +590,7 @@
if (type.IsFixedSizeArray()) {
auto size =
std::get<FixedSizeArray>(type.GetArray()).dimensions.front()->EvaluatedValue<int32_t>();
- if (values_.size() > static_cast<size_t>(size)) {
+ if (values_.size() != static_cast<size_t>(size)) {
AIDL_ERROR(this) << "Expected an array of " << size << " elements, but found one with "
<< values_.size() << " elements";
err = -1;