Drop string-content truthiness; &&/|| return operands#16
Merged
Conversation
What:
- IsTruthy no longer treats "false" (case-insensitive) as falsey. A
non-empty string is truthy regardless of content; empty strings stay
falsey. bool("false") is now true.
- && and || return the deciding operand (Python and/or semantics)
instead of a coerced bool. Short-circuit behavior is unchanged.
- Spec, llms.txt, and tests updated. Templates and higher-order-patterns
guides left alone; they tie into the upcoming `if` builtin step.
Why:
- The "false" string special-case was a footgun in JSON-heavy contexts
and would have been actively harmful once && and || started returning
operands (a bare `name` of "false" would falsey-fall-through).
- Operand-returning logical ops compose cleanly with truthiness for
idioms like `name || "(none)"`, `xs || []`, and `count || 0`. This
also subsumes a `default(x, y)` builtin, so we will not add one.
Together these are step 1 of docs/design/language-evolution.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
truthy.go):IsTruthyno longer special-cases the string"false". A non-empty string is truthy regardless of content; empty strings stay falsey.bool("false")is nowtrue.program.go):&&and||return the deciding operand (Pythonand/orsemantics) instead of a coerced bool. Short-circuit behavior is unchanged.Why
The
"false"-string carve-out was a footgun in JSON-heavy contexts and becomes actively harmful once&&/||return operands (a bare identifier carrying the string"false"would falsey-fall-through unexpectedly).Operand-returning logical ops compose cleanly with the new truthiness rules:
This subsumes a
default(x, y)builtin, so per the design doc we are not adding one. Hard bool casts remain available viabool(v).Docs and tests
docs/reference/spec.md: Logical and Truthiness sections rewritten.llms.txt: bullets updated.engine_test.go: addedTestEval_LogicalReturnsOperandpinning the new operand-returning behavior.script_test.go,boundaries1_test.go,boundaries2_test.go: updated three existing assertions that depended on the dropped string-content rule.ifbuiltin lands (a later step in the design doc).Test plan
go test ./...go test -race ./...FuzzCompile20sFuzzEval20sFuzzTemplateEval15s