Repository navigation
A compiled statement asked for as a number is its truth value - #2228
Merged
Merged
Conversation
In the LINQ compiler, a statement compiled to a number, as Compile<double, double> or Compile<Complex, Complex>, threw InvalidProtocolProvided: "NaN conversion not implemented for System.Boolean". That exception says the caller's protocol is wrong, and no protocol had been given. A provided statement threw the same, and a piecewise of statements threw KeyNotFoundException, from MaxType's table of numeric types. All three are on 2.6.0 as well. The root is that ConvertNaN had no case for a statement. In three-valued logic a statement with no truth value is null, so ConvertNaN(bool) is now a null bool?. On top of that: - ConvertType takes a statement to a number by its Iverson value: 1, 0, or NaN where it has none. That is what FastExpression and an Iverson bracket give. - A provided statement is a bool?, with no truth value where its predicate fails. - A piecewise whose cases are all statements is a bool?. One that mixes statements and numbers is refused with UncompilableNodeException. - A statement that may have no truth value, asked for as long or int, which have no NaN, is refused the same way. StatementAsANumberCompilationTest compares eight statements, among them a provided and a piecewise one, as Complex and as double against FastExpression, at 12 points that include i, NaN and +oo. It also checks provided and piecewise statements as bool?, and the two refusals. All 17 fail on master. A statement in a numeric position, such as sin(x > 1), is a different defect, #2227. Fixes #2224. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2228 +/- ##
==========================================
- Coverage 86.67% 86.66% -0.02%
==========================================
Files 309 309
Lines 67644 67660 +16
Branches 19612 19621 +9
==========================================
+ Hits 58629 58635 +6
- Misses 4896 4907 +11
+ Partials 4119 4118 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Fixes #2224.
In the LINQ compiler, a statement compiled to a number, as
Compile<double, double>orCompile<Complex, Complex>, threwInvalidProtocolProvided: NaN conversion not implemented for System.Boolean. That exception says the caller's protocol is wrong, and none had been given. Aprovidedstatement threw the same. Apiecewiseof statements threwKeyNotFoundException, fromMaxType's table of numeric types.The root is that
ConvertNaNhad no case for a statement. In three-valued logic a statement with no truth value isnull, soConvertNaN(bool)is now anullbool?. On top of that:ConvertTypetakes a statement to a number by its Iverson value:1,0, orNaNwhere it has none. That is what FastExpression and an Iverson bracket give.providedstatement is abool?, with no truth value where its predicate fails.piecewisewhose cases are all statements is abool?. One that mixes statements and numbers is refused withUncompilableNodeException.longorint, which have noNaN, is refused the same way."x > 1".ToEntity().Compile<double, double>("x")(2)InvalidProtocolProvided1"x > 1 provided x > 0".ToEntity().Compile<double, bool?>("x")(-1)InvalidProtocolProvidednull"piecewise(x > 1 provided x > 0, x < -1)".ToEntity().Compile<double, bool?>("x")(-2)KeyNotFoundExceptiontrueTests.
StatementAsANumberCompilationTesthas 17 cases, and all fail on master:providedand apiecewiseone, compiled asComplexand asdoubleand compared with FastExpression at 12 points, includingi,NaNand+oo;providedandpiecewisestatements compiled asbool?;Full suite 18042/0, interactive trio, AOT smoke 73/0, all frameworks build.
A statement in a numeric position, as in
sin(x > 1), is a different defect, filed as #2227.🤖 Generated with Claude Code