Skip to content

fix(z3linq,#17302): short (Int16) symbols never read back -- checked ToInt16 conversion - #32

Merged
jsboige merged 1 commit into
mainfrom
fix/int16-read-roundtrip-17302
Sep 23, 2026
Merged

jsboige merged 1 commit into
mainfrom
fix/int16-read-roundtrip-17302

Conversation

@jsboige

@jsboige jsboige commented Sep 21, 2026

Copy link
Copy Markdown

Grain: FIX/dotnet-lib -- lane myia-po-2026:CoursIA -- prev: CONTENU/notebook-python #17312

short (Int16) symbols never read back from a solved model (#17302, CoursIA)

Defect — both read switches folded TypeCode.Int16 into the Int32 arm:

case TypeCode.Int16:
case TypeCode.Int32:
    value = ReadIntegral(val, asInt64: false);   // returns int

ReadIntegral(..., asInt64: false) returns an Int32; PropertyInfo.SetValue on a short property then throws ArgumentException ("Object of type 'System.Int32' cannot be converted to type 'System.Int16'") — after a successful solve. Any theorem carrying a short member was unusable, and the failure read as a solver crash. Two sites: the property read in ConvertZ3Expression and the collection-element read in ConvertScalarExpr.

Fix — the Int16 arm reads wide (asInt64: true) and converts through a checked ToInt16(long, string) that throws OverflowException naming the symbol on out-of-range values, mirroring ToDateTime (endjin#87 pattern). The out-of-type control is a checked read, not a removed one.

.deploy/Z3.Linq.dll rebuilt from the Release output — postmortem of #27: a source-only fix leaves the tracked artifact byte-identical and the 17 notebooks binding #r "../Z3.Linq/.deploy/Z3.Linq.dll" keep the defect. SHA changed abd7d898… → a25ed0e8….

Orthogonality (measured) — the defect precedes and is independent of the bounds port (#17301, PR #31): the CoursIA issue reports the same exception with AssertBounds disabled, and this fix touches only the read path while #31 touches the write path.

Validation

Proof Result
New tests 7 — Solve_ShortAtEveryBoundary_RoundTrips (Theory: MinValue, MaxValue, 0, −123, 12345), Solve_ShortListRoundTripsEveryElement (collection path), Solve_ShortBeyondRange_ThrowsNamingTheSymbol (checked read)
Full suite 94/94 green, 0 warning (dotnet test -c Release, net8.0)
Regression scope Int32/Int64/DateTime/decimal/double/bool arms untouched — their tests (87) pass byte-for-byte unchanged

See jsboige/CoursIA#17302 (acceptance covered in full: satisfiable round-trips at every boundary, out-of-type control preserved as a naming checked read, no regression on existing types).

🤖 Generated with Claude Code

…ToInt16 conversion

The read path folded Int16 into the Int32 arm of both switches (property
read in ConvertZ3Expression, element read in ConvertScalarExpr): ReadIntegral
(asInt64: false) returns an int, and PropertyInfo.SetValue on a short
property throws ArgumentException after a successful solve -- satisfiable
theorems on short members were unusable, and the failure read as a solver
crash. The Int16 arm now reads wide (asInt64: true) and converts through a
checked ToInt16 that names the symbol on overflow, mirroring ToDateTime.

.deploy/Z3.Linq.dll rebuilt from the Release output so the fix reaches the
notebooks (postmortem of #27: a source-only fix leaves the tracked artifact
byte-identical and 17 notebooks keep the defect).

Tests: 7 new (5 boundary round-trips incl. MinValue/MaxValue, list element
round-trip on the collection path, out-of-range OverflowException naming the
symbol), suite 94/94 green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

94 tests   94 ✅  3s ⏱️
 1 suites   0 💤
 1 files     0 ❌

Results for commit 5ad0c7b.

myia-ai-01 pushed a commit to jsboige/CoursIA that referenced this pull request Sep 22, 2026
…x (fork PR #32) (#17318)

Bumps MyIA.AI.Notebooks/SymbolicAI/SMT/Z3.Linq 20984bfd -> 5ad0c7b: the Int16
read arm no longer folds into Int32 (PropertyInfo.SetValue ArgumentException
after a successful solve); checked ToInt16 names the symbol on overflow;
.deploy/Z3.Linq.dll rebuilt so the 17 notebooks binding it get the fix.
Fork suite 94/94 green.

Merge order: fork PR MyIntelligenceAgency/Z3.Linq#32 first.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@jsboige
jsboige merged commit 237b05e into main Sep 23, 2026
10 of 11 checks passed
jsboige pushed a commit that referenced this pull request Sep 23, 2026
…th fixes

Built from the rebased head (237b05e, #32 Int16 read-back merged): the wrapper
now carries the Int16 arm and the scalar bounds in one binary. A binary DLL
cannot be merged, so this is a rebuild rather than a resolution.

Verified on the artifact: ToInt16, AssertBounds, GetBounds, SymbolType and the
fork's CollectionHandling are all present in the rebuilt assembly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
jsboige pushed a commit that referenced this pull request Sep 23, 2026
…jette toujours

Interaction entre les deux correctifs, mesuree apres rebase sur 237b05e :
b.S > short.MaxValue n'est plus satisfiable, puisque le symbole scalaire est
desormais borne a la plage de son type -- le read verifie n'est plus atteint,
donc Solve() rend null au lieu de lever OverflowException. Le test de #32
pinnait l'ancienne premisse ("the symbol is an unbounded integer to Z3").

Forme retenue : celle du precedent DateTime de cette meme PR, ou le scalaire
hors bornes est UNSAT et ou la couverture du read verifie est deplacee vers le
chemin collection -- les bornes n'atteignent pas les elements, dont la longueur
n'est pas connue a la construction du theoreme. Regle anti-regression : on
deplace la couverture, on ne la supprime pas. Le jumeau ajoute
Solve_ShortInListBeyondRange_StillThrowsNamingTheSymbol passe, ce qui mesure que
le chemin element jette bien toujours.

dotnet test : 102 reussis, 0 echec (94 a la base 6ac5b80, +7 des tests Int16
de #32, +1 de la scission).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant