AAPT2: Fix issue with enums and integer attributes
When an attribute had the format "enum|integer", and a max or min
allowed value set, any value set for this attribute would have its
enum symbol's value checked against the valid integer range.
This would lead to the following:
android:numColumns="autofit"
being interpreted as an integer value of -1, which violated the minimum
expected value for numColumns, which was 0.
Bug: 62358540
Test: make aapt2_tests
Change-Id: I3150410448a533d3595a08ac6b2966264db874d8
diff --git a/tools/aapt2/link/ReferenceLinker.cpp b/tools/aapt2/link/ReferenceLinker.cpp
index a8e510c..414e56e 100644
--- a/tools/aapt2/link/ReferenceLinker.cpp
+++ b/tools/aapt2/link/ReferenceLinker.cpp
@@ -109,18 +109,15 @@
entry.value->Accept(this);
// Now verify that the type of this item is compatible with the
- // attribute it
- // is defined for. We pass `nullptr` as the DiagMessage so that this
- // check is
- // fast and we avoid creating a DiagMessage when the match is
- // successful.
- if (!symbol->attribute->Matches(entry.value.get(), nullptr)) {
+ // attribute it is defined for. We pass `nullptr` as the DiagMessage so that this
+ // check is fast and we avoid creating a DiagMessage when the match is successful.
+ if (!symbol->attribute->Matches(*entry.value, nullptr)) {
// The actual type of this item is incompatible with the attribute.
DiagMessage msg(entry.key.GetSource());
// Call the matches method again, this time with a DiagMessage so we
// fill in the actual error message.
- symbol->attribute->Matches(entry.value.get(), &msg);
+ symbol->attribute->Matches(*entry.value, &msg);
context_->GetDiagnostics()->Error(msg);
error_ = true;
}