Skip to content

Commit

Permalink
core: Fix bug for multiple consecutive map conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Jan 15, 2025
1 parent 0818796 commit 07f3f5e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
14 changes: 13 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
{
"calva.fmt.configPath": ".cljfmt.edn",
"cSpell.words": [
"amap",
"arity",
"automount",
"butlast",
"cmnd",
"concat",
"cond",
"condp",
"construct",
"csys",
"cusr",
"Datamon",
"debuginfo",
"defmacro",
"defn",
"defns",
"defsyn",
"dissoc",
"distclean",
"dmap",
"doall",
Expand All @@ -33,6 +38,7 @@
"ingydotnet",
"isolatethread",
"libyamlscript",
"mapcat",
"mapv",
"markys",
"Mita",
Expand All @@ -43,6 +49,7 @@
"nums",
"parens",
"pprint",
"prewalk",
"println",
"Raku",
"Seajure",
Expand All @@ -51,6 +58,7 @@
"serviceaccount",
"sexpr",
"sexprs",
"splt",
"taptest",
"templating",
"tolerations",
Expand All @@ -60,11 +68,15 @@
"truey",
"trunc",
"unoptimized",
"vect",
"vstr",
"wallclock",
"xmap",
"xtrace",
"yamlscript",
"ysexpr",
"ysexprs"
"ysexprs",
"zipmap"
],
"java.configuration.updateBuildConfiguration": "disabled",
"makefile.configureOnOpen": true
Expand Down
27 changes: 13 additions & 14 deletions core/src/yamlscript/constructor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,21 @@
(map
(fn [node]
(let [node (construct-node node ctx)]
(if (vector? node)
(first node)
node)))
(if (vector? node) (first node) node)))
(mapcat rest part))))]
(Lst [(Sym 'let) bind dmap]))
(let [form (get-in part [0 0])
form (construct-node form ctx)
form (if (map? form)
form
(if (= 1 (count form))
(first form)
(Lst (apply vector (Sym 'do) form))))]
(if (= dmap {:Map []})
form
(Lst [(Sym 'merge) form dmap])))))
dmap (vec (reverse parts)))]
(reduce (fn [dmap [form]]
(let [form (construct-node form ctx)
form (if (map? form)
form
(if (= 1 (count form))
(first form)
(Lst (apply vector (Sym 'do) form))))]
(if (= dmap {:Map []})
form
(Lst [(Sym 'merge) form dmap]))))
dmap (reverse part))))
dmap (reverse parts))]
result))

(defn construct-dmap [node ctx]
Expand Down
13 changes: 13 additions & 0 deletions core/test/compiler-stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,16 @@
- :when x: -[2 3 4]
clojure: |
(concat (when x [2 3 4]))
- name: Two '::' in a row in a data mode mapping
yamlscript: |
!yamlscript/v0:
a: 1
:when x: -{'b' 2}
:when y:: {c: 3}
d: 4
clojure: |
(merge
{"a" 1}
(merge (when x {"b" 2}) (merge (when y {"c" 3}) {"d" 4})))

0 comments on commit 07f3f5e

Please sign in to comment.