Repository navigation
Description
A Starlark caller passing an integer where a provider method declares a string gets the rune at that code
point, silently. print(65) emits A. print(42) emits *.
Measured directly against op.Convert:
Convert(int64(65) -> string) = "A", err=<nil>
Convert(int64(42) -> string) = "*", err=<nil>
Mechanism
pkg/op/convert.go:173:
if elem.Type().ConvertibleTo(target) {
return elem.Convert(target).Interface(), true
}In Go, an integer type is convertible to string, and the conversion yields the character with that code
point rather than the decimal text. reflect.Value.Convert performs exactly the same conversion as string(i).
go vet's stringintconv analyzer exists to catch this, and it cannot see through reflection — so the vet
gate we run passes over it.
Why it matters
It is silent. There is no error, no warning, and the resulting string is plausible-looking garbage. A script
author writing note(count) instead of note(str(count)) gets a control character, not a message, and
nothing in the output says why.
It applies to every provider method with a string parameter, not one provider. float behaves the same
way, and a bool is correctly rejected — bool value is neither assignable nor convertible to string — which
makes the int case look even more like intended behavior by contrast.
Found via
Adding e2e coverage for #708. The fixture asserted print(42) fails with expected string, got int, which is
what toGoScalar's starlark.AsString path would produce. It does not fail: dispatch reaches op.Convert
first, and that path converts. Two conversion routes disagree about whether an int is a string, and the
permissive one wins.
Note this also means #708's design doc, commit message, and PR body assert the wrong behavior for print(42).
Correcting there.
Proposal
Exclude integer and float kinds from the string target in tryConvertible, so they fall through to the
"neither assignable nor convertible" error that bool already gets. A caller wanting text writes str(x),
which is Starlark's own rendering and correct by construction.
Worth checking whether any current caller depends on the rune behavior. Nothing should.
Acceptance
-
print(65)reports a type error rather than emittingA -
str(65)still works and yields"65" - The same holds for every provider method with a string parameter, not just
ui - A test pins it, and is proved to fail against the current behavior
Plan and design documents
| Kind | Document |
|---|---|
| Plan | docs/plans/lossless-conversions.md |
Activity
test(ui): e2e coverage in devlore-test, and proof the bytes reach the…
docs(ui): correct the print(42) claim, and record two traps for the n…
ui takes the root namespace and replaces print and fail (#708)
David-Noble-at-work commentedon Aug 27, 2026
Scoped, and it is four bugs sharing one mechanism rather than one. Plan:
docs/plans/lossless-conversions.md.Measured against
op.Convert:int64(65)→string"A"int64(300)→int844int64(-1)→uint8255float64(3.9)→int3All four silent, all four from the same
ConvertibleTobranch inconvertDirect.Correction to this issue as filed: it says
floatbehaves the same way asintfor string targets. It does not —float64 → stringis rejected, because Go only permits integer types to convert to string.bool → stringis likewise rejected. That contrast is exactly what makes the integer case read as deliberate.The fix cannot be a blanket rule by kind.
file.mkdir(mode=0o644)arrives as a Starlark int and must reachos.FileMode, auint32. Rejecting int→uint32 outright breaks it. The question is not which types are involved — it is whether this value survives the trip.Proposed rule: a numeric conversion is allowed exactly when it round-trips. Convert, convert back, compare. That covers three of the four rows and keeps
0o644 → uint32working, since it round-trips exactly.Integer → string is rejected outright rather than round-trip tested —
65 → "A" → 65would pass a naive round-trip and is still wrong. Nobody passing65to a string parameter means"A";str()exists and renders correctly by construction.Two open questions in the plan: whether
int64 → float64should get the same treatment (it loses precision for very large integers), and confirming the guard belongs inconvertDirect, where it would also govern slice elements, map values, and struct fields — which is the intent, but worth stating rather than discovering.David-Noble-at-work commentedon Aug 27, 2026
Ruling: conversions follow Python's rule, not Go's. Plan rewritten —
docs/plans/lossless-conversions.md.Category is decided by kind. Range is the only question a value gets asked, and only integer→integer asks it.
str(x)says it properlyTypeError: 'float' object cannot be interpreted as an integerstruct.error: byte format requires -128 <= number <= 1271 + 2.0)This replaces the round-trip rule I proposed earlier, and the difference matters. A round-trip test would accept
float(3.0) → int— it is integral and survives the trip — while rejecting3.9. Python rejects both:[1,2,3][1.0]is aTypeErrorregardless of the value being integral. A rule that accepts3.0and rejects3.9is one no author can predict, so category beats value.It also settles the open question about
int64 → float64: Python widens implicitly there, so it stays allowed with no check. I had been leaning toward applying a uniform round-trip rule, which would have caught large-integer precision loss. Python-like says leave it.Integer → string still needs rejecting by kind rather than by range —
65 → "A"round-trips back to65, so a value-based check lets it through.file.mkdir(mode=0o644)keeps working: integer→integer, in range. That is precisely why the rule cannot be "reject int→uint32".Out of scope, stated so it is not mistaken for an oversight:
string ↔ []bytestays implicit. Python requires explicit.encode()/.decode(), and Starlark has a distinctbytestype, so a strictly Python-shaped surface would change this — but it touches every provider method taking bytes and is much wider than int passed where a string is expected is silently converted to a rune: print(65) emits "A" #709.boolwhere an integer is wanted stays rejected. Python allows it (True == 1); this would be a loosening, and a bool arriving where a number is expected is far likelier to be a mistake than an intent.Placement: the guard goes in
convertDirect, where theConvertibleTobranch lives. That call is the last resort for the entire conversion ladder, so the rule will also govern slice elements, map values, and struct fields. Intended, and a wider blast radius than this issue's title suggests.David-Noble-at-work commentedon Aug 27, 2026
Blocked on #711. The serialization half has been backed out of the
lossless-conversionsbranch, leaving it purely about the conversion rule.Applying the category rule alone turns five existing tests red, all on save/load paths:
Not a defect in the rule —
LoadGraphuses plainjson.Unmarshal, so every number in a reloaded graph is afloat64, andConverthas been truncating it back. The rule removes the truncation and exposes what was underneath. That is #711, and it has to land first.A prototype of the fix also produced a checksum mismatch on reload, so it reaches graph identity rather than only deserialization — which is why it is its own issue rather than a step here.
The category-rule work stands and is proved: six tests written before the fix, each failing for its documented reason, now passing. One more still to update —
convert_struct_test.go:41hydrates a struct from a map with a literalfloat64reaching anintfield, no JSON involved. That test encodes the old lenient contract and belongs to this issue.fix(op): a reloaded number is read against the field it fills
docs(plans): number fidelity complete -- what step 5 and step 8 actua…
A reloaded number is read against the field it fills (#713)
Merge develop: number fidelity on reload (#713) unblocks the conversi…