Skip to content

Commit 04bd000

Browse files
Fix @optional for string literals (#905)
Signed-off-by: Michael Carlstrom <[email protected]>
1 parent e25eb4e commit 04bd000

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

rosidl_adapter/rosidl_adapter/parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,7 @@ def parse_message_string(pkg_name: str, msg_name: str,
530530
if not line:
531531
continue
532532

533-
annotation_index = line.rfind(OPTIONAL_ANNOTATION)
534-
if annotation_index >= 0:
533+
if line.startswith(OPTIONAL_ANNOTATION):
535534
if is_optional:
536535
raise MultipleOptionalAnnotations(
537536
f'Already declared @optional. Error detected with {line}.')

rosidl_adapter/test/data/msg/Test.expected.idl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module test_msgs {
88
module Test_Constants {
99
@optional
1010
const float INLINE_CONSTANT = 32.0;
11+
@optional
12+
const string OPTIONAL_STRING_CONST = "@optional";
1113
};
1214
@verbatim (language="comment", text=
1315
"msg level doc")
@@ -54,6 +56,10 @@ module test_msgs {
5456
@optional
5557
@default (value=32.0)
5658
float inline_default_optional;
59+
60+
@optional
61+
@default (value="@optional")
62+
string optional_default_string;
5763
};
5864
};
5965
};

rosidl_adapter/test/data/msg/Test.msg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ float32 multiline_optional
2222
@optional float32 inline_optional
2323
@optional float32 inline_default_optional 32.0
2424
@optional float32 INLINE_CONSTANT=32.0
25+
26+
@optional string optional_default_string @optional
27+
@optional string OPTIONAL_STRING_CONST=@optional

0 commit comments

Comments
 (0)