Error compiling specification with multiple WITH COMPONENTS constraints chained with OR operator
I have encountered error while trying to compile TS 102 894-2 v2.2.1 https://github.com/riebl/vanetza/blob/master/asn1/release2/TS102894-2v221-CDD.asn
[proc] [.\comptest\TS102894-2v221-CDD.asn] module ETSI-ITS-CDD (oid: [0, 4, 0, 5, 1, 102894, 2, 4, 1]): 341 ASN.1 assignments found
--- compilation cycle ---
Traceback (most recent call last):
File "D:\bp\pycrate\tools\pycrate_asn1compile.py", line 264, in <module>
sys.exit(main())
^^^^^^
File "D:\bp\pycrate\tools\pycrate_asn1compile.py", line 215, in main
compile_text(txt, **ckw)
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnproc.py", line 254, in compile_text
compile_modules(remain)
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnproc.py", line 942, in compile_modules
ObjNew = asnobj_compile(Obj)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnproc.py", line 876, in asnobj_compile
text = Obj.parse_def(Obj._text_def)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 1716, in parse_def
rest = self._parse_const(text)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 3964, in _parse_const
self._parse_const_val(const)
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 4033, in _parse_const_val
self.parse_set(const['text'])
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 5844, in parse_set
rest = self._parse_set_comp(rv, val, dom)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 6080, in _parse_set_comp
return self.parse_value(text)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 4611, in parse_value
return getattr(self, self._PARSE_VALUE_DISPATCH[self._type])(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 5486, in _parse_value_seqof
return self._parse_value_ref(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\dejfd\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pycrate_asn1c\asnobj.py", line 4626, in _parse_value_ref
raise(ASN1ProcTextErr('{0}: invalid value reference for {1}, {2}'\
pycrate_asn1c.err.ASN1ProcTextErr: EventZone: invalid value reference for SEQUENCE OF, (WITH COMPONENT (WITH COMPONENTS {..., eventDeltaTime PRESENT}))
I also reproduced the error with this minimal ASN.1 specification:
Test DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Test ::= SEQUENCE {
a INTEGER OPTIONAL,
b INTEGER OPTIONAL
} ((WITH COMPONENTS {..., a PRESENT}) | (WITH COMPONENTS {..., b PRESENT}))
END
Is this known limitation of pycrate?
Yes, the support of WITH COMPONENTS is buggy in the compiler. Additionally, I'm not sure it's also well implemented in the runtime side... Thank you for providing a minimal example exhibiting the issue.
Regarding the stack trace, it seems the compiler tries to parse a value constraint, and does not even enter the _parse_const_withcomps() method (https://github.com/pycrate-org/pycrate/blob/fe6a308dcee661de4276b49c68666f76998776d2/pycrate_asn1c/asnobj.py#L4258C9-L4258C32). This is clearly a problem here on the parsing of general constraints for SEQUENCE, SET and CHOICE (and maybe more).