Skip to content

Commit

Permalink
Disambiguate type names in cluster-objects initializers. (#13744)
Browse files Browse the repository at this point in the history
In most places, where we are assigning to something of type {{zapTypeToDecodableClusterObjectType type}} to start with, what we had was not a problem.

But in the DecodableType for the cluster-wide struct, which is inside
namespace chip::app::Clusters::ClusterName::Attributes, we could get
an ambiguity when an attribute and an enum had the same name
(e.g. HourFormat).  Then the bareword HourFormat instead of being
treated as ClusterName::HourFormat would get treated as
ClusterName::Attributes::HourFormat, which is a namespace, not a type
name, and after that things would fail to compile.

The fix is to, at this one callsite, pass in the cluster name as the
namespace, so we generate fully qualified names for enums.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 17, 2023
1 parent 9f7bdad commit 1002852
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{~#if_is_struct type}}
{{! Structs have their own initializers }}
{{~else~}}
= static_cast<{{zapTypeToEncodableClusterObjectType type}}>(0)
= static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>(0)
{{~/if_is_struct}}
{{~/unless}}
{{~/unless}}
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct TypeInfo
{{#zcl_attributes_server}}
{{! isOptional=false because optional attributes don't get represented
as Optional types here. }}
Attributes::{{asUpperCamelCase label}}::TypeInfo::DecodableType {{asLowerCamelCase label}}{{> cluster_objects_field_init isOptional=false}};
Attributes::{{asUpperCamelCase label}}::TypeInfo::DecodableType {{asLowerCamelCase label}}{{> cluster_objects_field_init ns=parent.name isOptional=false}};
{{/zcl_attributes_server}}
};
};
Expand Down
31 changes: 18 additions & 13 deletions zzz_generated/app-common/app-common/zap-generated/cluster-objects.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1002852

Please sign in to comment.