Repository navigation
Read static members and captured member chains as constants - #118
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation and regression tests support the intended behavior, with no unresolved blocking issues identified.
No open issues 🎉
What changed in this PR
This PR extends constant-member translation so constraints can use static fields and properties directly, while fixing member chains rooted in captured variables.
Changes:
- Evaluate static and captured member chains at solve time, reading each member from the preceding value.
- Report null links with a
NotSupportedExceptionidentifying the expression. - Add 10 regression tests covering DateTime boundaries, static members, chained access, and null handling.
| File | Description |
|---|---|
| solutions/Z3.Linq/ExpressionVisitor.cs | Resolve static and captured member chains as constants with explicit null diagnostics. |
| solutions/Z3.Linq.Tests/ConstantMemberTests.cs | Add regression coverage for constant-member evaluation and solve-time behavior. |
Review effort: Balanced
Test Results 1 files 1 suites 11s ⏱️ Results for commit 03d264d. ♻️ This comment has been updated with latest results. |
MikeEvansLarah
previously approved these changes
Oct 27, 2026
Two ways a constraint naming a value, rather than a symbol, failed in VisitMember. A static field or property threw "Unknown parameter encountered". A const is folded by the compiler, but a static readonly field is not - DateTime.MaxValue, MinValue and UnixEpoch are all static readonly - and nor is a static property, so the tree carries a member access with no instance, which the visitor had no case for. So `t.X1 == DateTime.MaxValue` could not be written inline, and the existing DateTime tests got round it by copying the boundary into a local. A chain that starts at a static member is now read and translated as a constant, like one that starts at a captured variable. It is read when the theorem is solved, as a captured local is. A chain of members on a captured variable threw TargetException. `holder.In.Value` is three members starting at the closure constant, and the loop read each of them from the closure instead of from the previous member's value, so any chain longer than one failed. Each member is now read from the value before it, and a link that is null is refused with a message naming it. Inline `t.X1 > DateTime.MaxValue` now reaches Z3 and has no solution, because the symbol is bounded to the DateTime range (#98). Reported by jsboige on #110. jsboige's #113 fixes the DateTime fields on feature/datetime-ticks; this covers every static field and property. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HowardvanRooijen
dismissed
MikeEvansLarah’s stale review
October 28, 2026 07:38
The merge-base changed after approval.
HowardvanRooijen
force-pushed
the
fix/static-member-constants
branch
from
October 28, 2026 07:38
18978e7 to
03d264d
Compare
Code Coverage Summary Report - Linux (No TFM)Summary
CoverageZ3.Linq - 93.6%
Z3.Linq.Examples - 70.7%
|
MikeEvansLarah
approved these changes
Oct 28, 2026
jsboige
pushed a commit
to MyIntelligenceAgency/Z3.Linq
that referenced
this pull request
Nov 4, 2026
Build green (0 warnings under TreatWarningsAsErrors), 371/372 tests passing. Aligns the rebased partial-eval branch with the newer upstream base: GetEnvironment/GetSolution call sites after the expression-visitor rewrite (endjin#100); ExtractCollection now uses upstream template-length sizing, the complete ReadZ3Value scalar conversion, EvaluateWithCompletion for free elements, and the no-length NotSupportedException parity. Keystone CollectionHandling tests moved to MSTest.Sdk/Shouldly. One expected failure remains: Solve_MemberChainThroughANull_ThrowsNamingTheExpression (endjin#118) - the global PartialEval fold preempts the null member-chain path. Co-Authored-By: Claude-Code <noreply@anthropic.com>
jsboige
added a commit
to MyIntelligenceAgency/Z3.Linq
that referenced
this pull request
Nov 5, 2026
Rebase onto current main (964f177, including the endjin#100 expression-visitor rewrite and endjin#118) and port the xUnit smoke suite to MSTest/MTP + Shouldly, aligned with the rest of the solution, as requested in review. The ten facts keep their semantics: integer and boolean symbols over anonymous-type environments, chained Where constraints, tuple readback, contradiction-to-null, Distinct, and Optimize in both directions. The xUnit project is gone - the tests now live in the existing MTP test project as a single file, so the PR adds coverage without a second harness. Measured: full suite 378/378 passing (368 on main + these 10), 4.9s; BasicTheoremTests alone 10/10, 328ms. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Two ways a constraint that names a value, rather than a symbol, failed in
VisitMember.Static fields and properties
The compiler folds a
const(such asint.MaxValue), but it does not fold astatic readonlyfield or a static property.DateTime.MaxValue,MinValueandUnixEpochare all static readonly, so the tree carries a member access with no instance, and the visitor had no case for one. The same failure hit any user-defined static readonly field or static property. The existing DateTime tests avoided it by copying the boundary into a local first.A chain that starts at a static member is now read and translated as a constant, like one that starts at a captured variable. It is read when the theorem is solved, as a captured local is, so a change between
WhereandSolveis seen.Member chains on a captured variable
The loop over the chain read every member from the closure instead of from the previous member's value, so any chain longer than one member threw. Each member is now read from the value before it. A link that is null is refused with a
NotSupportedExceptionthat names it.Tests
The new
ConstantMemberTestshas 10 tests, and all of them failed before the change: inlineDateTime.MaxValue,MinValueandUnixEpoch;t.X1 > DateTime.MaxValue, which now reaches Z3 and has no solution because the symbol is bounded to the DateTime range (#98); a static readonly field; a static property; a mutable static field, which is read at solve time; member chains on a captured variable and on a static member; and a chain through a null. 368 tests pass, and all six demos run.Relation to #113 and #43
jsboige reported this on #110, and their #113 fixes the
DateTimefields specifically, onfeature/datetime-ticks. This PR covers every static field and property, at the top of the stack. #43, which partially evaluates each constraint before visiting it, would also fold these accesses. This change stands on its own either way.🤖 Generated with Claude Code