Skip to content

Commit 1579502

Browse files
committed
Unparsing: fix handling of missing fields for recurse_field
When instantiating a "node" configuration that contains recurse_field templates, Langkit should keep placeholder templates when processing recurse_field templates for "missing fields" (null field, or an empty list that unparsing must treat as a missing field). Before this fix, the engine did not have such placeholder, and so did not have enough templates to build the vector of template arguments for all fields, leading to Constraint_Error exceptions.
1 parent 7f76991 commit 1579502

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

langkit/support/langkit_support-generic_api-unparsing.adb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,9 @@ package body Langkit_Support.Generic_API.Unparsing is
16811681

16821682
Arguments.Field_Docs.Append
16831683
(Pool.Create_List (Items));
1684+
else
1685+
Arguments.Field_Docs.Append
1686+
(Pool.Create_Empty_List);
16841687
end if;
16851688
end;
16861689
end loop;

testsuite/tests/ada_api/unparsing/cmd_recurse_field.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
{
22
"node_configs": {
3+
"ParamSpec": {
4+
"node": [
5+
{"kind": "recurse_field", "field": "f_name"},
6+
"softline",
7+
{"kind": "text", "text": ":"},
8+
"softline",
9+
{"kind": "recurse_field", "field": "f_type_expr"},
10+
"line",
11+
{"kind": "recurse_field", "field": "f_default_expr"}
12+
],
13+
"fields": {
14+
"f_default_expr": ["line", "recurse"]
15+
}
16+
},
317
"VarDecl": {
418
"node": [
519
{"kind": "recurse_field", "field": "f_is_null"},

testsuite/tests/ada_api/unparsing/commands.adb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ begin
107107
Check ("cmd_literalline.json");
108108
Check ("cmd_markasroot.json");
109109
Check ("cmd_recurse.json");
110-
Check ("cmd_recurse_field.json");
110+
Check
111+
("cmd_recurse_field.json",
112+
"var i: Int = 0;" & ASCII.LF
113+
& "def f(i: Int): Int {i;}");
111114
Check
112115
("cmd_recurse_flatten.json",
113116
"var i: Int = AAAAAAAAAAAAAAAAAA"

testsuite/tests/ada_api/unparsing/test.out

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,46 @@ Done.
636636
},
637637
{
638638
"kind": "text",
639-
"text": ";"
639+
"text": ";def f(i"
640+
},
641+
{
642+
"kind": "command",
643+
"command": {
644+
"command": "line",
645+
"literal": false,
646+
"soft": true,
647+
"hard": false
648+
}
649+
},
650+
{
651+
"kind": "text",
652+
"text": ":"
653+
},
654+
{
655+
"kind": "command",
656+
"command": {
657+
"command": "line",
658+
"literal": false,
659+
"soft": true,
660+
"hard": false
661+
}
662+
},
663+
{
664+
"kind": "text",
665+
"text": "Int"
666+
},
667+
{
668+
"kind": "command",
669+
"command": {
670+
"command": "line",
671+
"literal": false,
672+
"soft": false,
673+
"hard": false
674+
}
675+
},
676+
{
677+
"kind": "text",
678+
"text": "):Int{i;}"
640679
}
641680
]
642681
}

0 commit comments

Comments
 (0)