Skip to content

Rust generator: invalid codegen for composite with sinceVersion #972

Closed
@injecto

Description

@injecto

For the sample schema:

<sbe:messageSchema
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:sbe="http://fixprotocol.io/2016/sbe"
	package="test_package"
	id="1"
	version="2"
	semanticVersion="5.0.0"
	byteOrder="littleEndian"
	xsi:schemaLocation="http://fixprotocol.io/2016/sbe sbe.xsd">
	<types>
		<composite name="messageHeader">
			<type name="blockLength" primitiveType="uint16" description="Length of the root of the FIX message contained before repeating groups or variable/conditions fields."/>
			<type name="templateId" primitiveType="uint16" description="Template ID used to encode the message."/>
			<type name="schemaId" primitiveType="uint16" description="ID of the system publishing the message."/>
			<type name="version" primitiveType="uint16" description="Schema version."/>
		</composite>

		<composite name="NewComposite" sinceVersion="1">
			<type name="f1" primitiveType="uint16" presence="optional" nullValue="0" semanticType="Int"/>
			<type name="f2" primitiveType="uint32" presence="optional" nullValue="0" semanticType="Int" offset="4"/>
		</composite>
	</types>
	<sbe:message name="Message" id="1">
		<field name="oldField" id="1" type="uint16" semanticType="Int"/>
		<field name="newField" id="2" type="NewComposite" presence="optional" sinceVersion="1" />
	</sbe:message>
</sbe:messageSchema>

CLI tool 1.30.0 generates Rust code that won't compile with the error:

error[E0609]: no field `acting_version` on type `&new_composite_codec::decoder::NewCompositeDecoder<P>`
   --> test_package/src/new_composite_codec.rs:102:21
    |
102 |             if self.acting_version > 0 && self.acting_version < 1 {
    |                     ^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `parent`, `offset`

The code sample:

        #[inline]
        pub fn f1(&self) -> Option<u16> {
            if self.acting_version > 0 && self.acting_version < 1 {
                return None;

While the decoder struct is

    #[derive(Debug, Default)]
    pub struct NewCompositeDecoder<P> {
        parent: Option<P>,
        offset: usize,
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions