Skip to content

String value "[]" is coerced to an empty list #583

Description

@logbie

Summary

A string whose value is exactly the two characters [] is coerced to an empty list instead of staying a Text value. Other bracket-containing strings (even "[1, 2]") are unaffected, so the trigger is very narrow: a string equal to a valid empty-list literal.

Minimal reproduction

store a as "[]"
display "expected Text, got: " with typeof of a

store b as "[1, 2]"
display "for contrast, [1, 2] is: " with typeof of b

Actual output:

expected Text, got: List
for contrast, [1, 2] is: Text

Expected output:

expected Text, got: Text
for contrast, [1, 2] is: Text

The same coercion happens when the value "[]" is produced at runtime, e.g. by substring or by with concatenation ("" with "[" with "" with "]" yields a List), and when returned from an action.

Impact

Any code that legitimately produces the string "[]" — e.g. a templating engine rendering an empty JSON array, or string-building that happens to form [] — gets a list value where a string is expected, leading to downstream type errors or silent wrong output. It's rare (surrounding content avoids it) but surprising and hard to diagnose.

Environment

  • wfl built from source at current main
  • rustc 1.94.1, cargo 1.94.1, Linux

Notes

Quoted string literals should never be reinterpreted as list literals. The parse/eval of a Text whose contents look like a collection literal should be independent of the string's characters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions