2026.05.14¶
YAML inputs with non-string dict keys (integers, dates, booleans) now flow through to the target language’s value-formatting path instead of being silently converted to string form. Languages that can represent the key natively (Python, Ruby, Clojure, Lua, Bash, and others) produce the corresponding literal; languages whose dict syntax requires string keys or a homogeneous typed map raise
~literalizer.exceptions.UnrepresentableInputError. The affected opt-out targets are the JSON family (already~literalizer.Json5,~literalizer.Jsonnet,~literalizer.Toml), the string-keyed attribute-set languages (~literalizer.Nix,~literalizer.Dhall,~literalizer.Cobol), the statically-typed-map languages whose typed-map syntax has not yet been generalized (~literalizer.Go,~literalizer.Kotlin,~literalizer.CSharp,~literalizer.Haskell,~literalizer.Scala,~literalizer.Dart,~literalizer.VisualBasic,~literalizer.FSharp,~literalizer.Zig,~literalizer.Odin,~literalizer.Nim,~literalizer.D,~literalizer.TypeScript,~literalizer.JavaScript), the languages that reject specific non-string key types at the language level (~literalizer.PhprejectsDateTimekeys,~literalizer.Vrejectsboolkeys), and the languages whose value ADTs do not currently model non-string keys (~literalizer.OCaml,~literalizer.Sml,~literalizer.R).~literalizer.literalize_callnow accepts avariable_formargument (NewVariableorExistingVariable) that wraps the rendered call in an idiomatic per-language variable binding (e.g.let my_data = make_widget(42);,const my_data = make_widget({ count: 42 });,my_data = make_widget(count=42)). Mutability and inference style are controlled by the per-languagedeclaration_styleandModifiersenums on the suppliedLanguageinstance.BothVariableFormsis rejected – emitting both a declaration and an assignment would invoke the target function twice – as isper_element=True(no per-element name vector) and any language whose call form is a statement rather than an expression (call_returns_expression=False). All three are surfaced as~literalizer.exceptions.UnsupportedCallShapeError. The same exception is raised for languages whose declaration template wraps or transforms the right-hand side in a way that is only valid for literal values – Tcl (needs[...]command substitution), Bash (needs$(...)command substitution), Objective-C (@(...)boxing of primitives), tagged-enum heterogeneous-strategy languages (Roc, Haskell, Elm, SML, OCaml, PureScript, F#), C / SystemVerilog / Fortran / Ada / Zig / D (struct-initializer or constructor wrapping derived from the value’s literal type), Elixir (call stubs need module scope, not the variable’s function body), Erlang, Forth, and Nim. Closes #1961.The internal
~literalizer._types.Valueand~literalizer._types.ValueInputaliases now permit any~literalizer._types.Scalaras a dict key, in preparation for surface formats that admit non-string dict keys. A new~literalizer.exceptions.UnrepresentableInputErrorand asupports_non_string_dict_keysclass attribute on~literalizer.Language(defaulting toTrue; overridden toFalseon~literalizer.Json5,~literalizer.Jsonnet, and~literalizer.Toml) wire a centralized guard at the dict-formatting boundary. The surface parsers still produce only string-keyed dicts, so behavior is unchanged.~literalizer.literalizenow accepts aref_valuesmapping from ref identifier to the value declared elsewhere for that ref. Languages whose$refrendering depends on the referenced type (V’s.clone()for arrays and maps, Mojo’s^for non-trivial values, C++’sstd::movefornon-trivially-copyablevalues) consult it to choose the right form; when omitted these languages keep their type-agnostic default.Vnow emits a bare identifier for scalar refs (int,bool,f64) becauseint.clone()is rejected by the V compiler;Mojodrops^for register-trivial scalars where it is a hard error under--Werror;Cppdropsstd::movefortrivially-copyablescalars where clang-tidy’shicpp-move-const-argrejects it. Preamble inference also walks the resolvedref_valuesso sum-type body declarations (Haskell’sdata Val, OCaml’sval_t, Roc’sVal, …) include the variants needed by the referenced types.SystemVerilog’sliteralizerejects scalar$refmarkers via~literalizer.exceptions.CallArgNotSupportedError: SV keys the variable declaration off the marker dict’s shape (_VKV name[]) and cannot produce a coherent declaration for a scalar referent.The
~literalizer._language.Language.format_call_ref_identifier,~literalizer._language.Language.format_call_arg_ref_identifier, and~literalizer._language.Language.format_call_arg_ref_identifier_consumablehooks now receive a second positional argument: theValuebehind the ref (orNonewhen the caller did not supplyref_values). This is a breaking change for custom~literalizer.Languageimplementations that override these hooks; most overrides ignore the new argument.~literalizer.Vnow defaultsheterogeneous_strategytoV.heterogeneous_strategies.ERRORand reportsdict_supports_heterogeneous_values=Falseandsupports_heterogeneity=Falseon its sequence and set formats. V is statically typed and rejects unwrapped heterogeneous collections, so rendering them now raises rather than emitting code the V compiler will not accept. Callers that want to materialize heterogeneous data must opt in toV.heterogeneous_strategies.INTERFACE, which wraps values withIVal(...)and emits theinterface IVal {}declaration as before.