Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use isSet in isUsed functions #655

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/extensions/cpp/freemarker/CompoundField.inc.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ${I}}
</#macro>

<#macro field_optional_condition field>
<#if field.optional.clause??>${field.optional.clause}<#else>${field.optional.isSetIndicatorName}()</#if><#t>
<#if field.optional.clause??>${field.optional.clause}<#else><@field_member_name field/>.hasValue()</#if><#t>
</#macro>

<#macro compound_write_field field compoundName indent packed=false>
Expand Down
2 changes: 1 addition & 1 deletion compiler/extensions/java/freemarker/Structure.java.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public class ${name} implements <#rt>
</#if>
public boolean ${field.optional.isUsedIndicatorName}()
{
return <#if field.optional.clause??>(${field.optional.clause});<#else>${field.optional.isSetIndicatorName}();</#if>
return <#if field.optional.clause??>(${field.optional.clause});<#else>(<@field_member_name field/> != null);</#if>
}

<#if withWriterCode>
Expand Down
2 changes: 1 addition & 1 deletion compiler/extensions/python/freemarker/Structure.py.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ ${I}<#rt>
"""

</#if>
return <#if field.optional.clause??>${field.optional.clause}<#else>self.${field.optional.isSetIndicatorName}()</#if>
return <#if field.optional.clause??>${field.optional.clause}<#else>not self.<@field_member_name field/> is None</#if>
<#if withWriterCode>

def ${field.optional.isSetIndicatorName}(self) -> bool:
Expand Down
5 changes: 5 additions & 0 deletions test/arguments/without_writer_code/zs/without_writer_code.zs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ union ExtraParamUnion
uint32 value32;
};

struct ItemWithOptionalField
{
optional uint16 opt;
};

struct Item(ItemType itemType)
{
uint16 param;
Expand Down
Loading