Skip to content

Say which variable a compiled expression was not given - #688

Merged
Happypig375 merged 1 commit into
ASC-Community:masterfrom
Rafael-SOWNet:fix/compile-unbound-variable
Aug 4, 2026
Merged

Happypig375 merged 1 commit into
ASC-Community:masterfrom
Rafael-SOWNet:fix/compile-unbound-variable

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member
"a * x".ToEntity().Compile("x");
// KeyNotFoundException: The given key 'a' was not present in the dictionary

That names neither the variable, nor the compilation, nor anything a caller of Compile could act on. Both compilers did it — the one into a FastExpression and the one into a Linq expression tree — each by reaching into its own dictionary of arguments and letting the lookup fail.

Now

UncompilableNodeException: a is not among the variables the expression is being compiled over, which are x
UncompilableNodeException: y is not among the variables the expression is being compiled over, which are none

A compiled expression is a function of the variables it was compiled over, so one it does not mention is not something it can be given a value for. UncompilableNodeException is what both compilers already raise for a matrix or a derivative, so this is the exception a caller would already be catching.

Constants are unaffected: pi and e are substituted for their values before any variable is looked up, so "pi * x" still compiles over x alone.

Verification

13 tests, 8 of which fail without the change — 5 of those on the fast compiler, 3 on the Linq one. 4009 unit tests and 127 F# tests on both target frameworks, none failing.

No issue is filed for this; I found it sweeping the compilers against interpreted evaluation.

"a * x".ToEntity().Compile("x") raised

    KeyNotFoundException: The given key 'a' was not present in the dictionary

which names neither the variable, nor the compilation, nor anything a caller of
Compile could act on. Both compilers did it: the one into a FastExpression and
the one into a Linq expression tree, each by reaching into its own dictionary of
arguments and letting the lookup fail.

A compiled expression is a function of the variables it was compiled over, so
one it does not mention is not something it can be given a value for. That is
now an UncompilableNodeException, which is what the compilers already raise for
a matrix or a derivative, and it names the variable and the ones that were
given.

Constants are unaffected: pi and e are substituted for their values before any
variable is looked up, so "pi * x" still compiles over x alone.

13 tests, 8 of which fail without the change. 4009 in all, 127 F#.
@Happypig375
Happypig375 merged commit 7f1b4f2 into ASC-Community:master Aug 4, 2026
24 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.42%. Comparing base (90c00a8) to head (ae64f4a).
⚠️ Report is 57 commits behind head on master.

Files with missing lines Patch % Lines
...Functions/Compilation/IntoLinq/IntoLinqCompiler.cs 90.90% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #688      +/-   ##
==========================================
- Coverage   80.99%   80.42%   -0.58%     
==========================================
  Files         155      156       +1     
  Lines       13687    12917     -770     
  Branches     1957     2122     +165     
==========================================
- Hits        11086    10388     -698     
+ Misses       1990     1921      -69     
+ Partials      611      608       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet deleted the fix/compile-unbound-variable branch August 4, 2026 20:49
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.

3 participants