Skip to content

Fix/bad syntax binding error variants #6343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Conversation

jcnelson
Copy link
Member

Description

This PR improves the expressiveness of CheckErrors::BadSyntaxBinding and some related binding errors to indicate both the kind of binding considered, as well as the specific structural deficiency. Specifically, it differentiates between faulty let-bindings, function definitions, and tuple constructors, and it treats all instance of invalid type signatures found in top-level definitions as CheckErrors::BadSyntaxBinding while reporting the inner CheckErrors error message and innermost faulty binding in the signature.

For example, in develop today, these errors are reported.

$ echo '(let ((u1 u2)) true)' | clarity-cli eval_raw - | jq -r '.error.analysis' | head -n 1
BadSyntaxBinding
$ echo '(define-public (foo (string -19)) (ok true))' | clarity-cli eval_raw - | jq -r '.error.analysis' | head -n 1
BadSyntaxBinding
$ echo '(tuple oops (foo u1))' | clarity-cli eval_raw - | jq -r '.error.analysis' | head -n 1
TupleExpectsPairs

In this PR, these same errors are as follows:

$ echo '(let ((u1 u2)) true)' | /tmp/clarity-cli eval_raw - | jq -r '.error.analysis' | head -n 1
BadSyntaxBinding(NotAtom(Let, 0, SymbolicExpression { expr: LiteralValue(UInt(1)), id: 5 }))
$ echo '(define-public (foo (string -19)) (ok true))' | /tmp/clarity-cli eval_raw - | jq -r '.error.analysis' | head -n 1
BadSyntaxBinding(BadTypeSignature(0, SymbolicExpression { expr: LiteralValue(Int(-19)), id: 7 }, "supplied type description is invalid"))
$ echo '(tuple oops (foo u1))' | /tmp/clarity-cli eval_raw - | jq -r '.error.analysis' | head -n 1
BadSyntaxBinding(NotList(TupleCons, 0, SymbolicExpression { expr: Atom(ClarityName("oops")), id: 3 }))

Right now, this PR does not touch CheckErrors::BadMayTypeDefinition, but I'm happy to add that as well.

Applicable issues

Additional info (benefits, drawbacks, caveats)

Looking at where the errors were used, it does not appear that any changes are consensus critical. I could not find any place in the codebase where the caller matches on a CheckErrors value affected by this PR.

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

jcnelson added 20 commits July 31, 2025 16:46
… formatting code) to specialize CheckErrors::BadSyntaxBinding. Also, remove tuple-specific bad syntax binding errors since they are now captured by BadSyntaxBinding
…e-bindings, report the specific kind of error instead of the generic BadSyntaxBinding
…kind of binding being checked so an error will result in a meaningful message
…ype-check being performed so error messages can reflect it
… to now check for the specific variant of BadSyntaxBinding. Also, add comprehensive checks for each variant of BadSyntaxBinding, as well as test to verify that error messages do not grow unbound with the type's nesting depth
…nding error and the specific context in which it occurs
…reporting, and consolidate Display implementation for SymbolicExpression and SymbolicExpressionType
…and update tests to expect when BadSyntaxBinding wraps another CheckErrors variant
…g expecting it to wrap an inner CheckErrors variant which lead to a bad binding
…xBindingError::BadTypeSignature(..) ..), instead of BadSyntaxExpectedListOfPairs, so the caller has a better idea about what is structurally deficient about the binding or type signature
@jcnelson jcnelson requested review from a team as code owners July 31, 2025 21:38
@jcnelson jcnelson changed the base branch from master to develop July 31, 2025 21:38
@jcnelson jcnelson requested review from kantai and obycode August 1, 2025 15:32
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 86.99634% with 71 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.73%. Comparing base (799953e) to head (1396f49).
⚠️ Report is 11 commits behind head on develop.

Files with missing lines Patch % Lines
...ty/src/vm/analysis/type_checker/v2_05/tests/mod.rs 43.47% 26 Missing ⚠️
...ity/src/vm/analysis/type_checker/v2_1/tests/mod.rs 84.88% 26 Missing ⚠️
clarity/src/vm/analysis/errors.rs 86.11% 10 Missing ⚠️
...y/src/vm/analysis/type_checker/v2_1/natives/mod.rs 87.50% 7 Missing ⚠️
.../src/vm/analysis/type_checker/v2_05/natives/mod.rs 94.73% 2 Missing ⚠️

❌ Your project check has failed because the head coverage (72.73%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6343      +/-   ##
===========================================
- Coverage    81.00%   72.73%   -8.28%     
===========================================
  Files          541      541              
  Lines       347855   348261     +406     
===========================================
- Hits        281772   253293   -28479     
- Misses       66083    94968   +28885     
Files with missing lines Coverage Δ
clarity/src/vm/analysis/read_only_checker/mod.rs 87.81% <100.00%> (+1.17%) ⬆️
clarity/src/vm/analysis/tests/mod.rs 76.67% <100.00%> (-23.33%) ⬇️
clarity/src/vm/analysis/type_checker/v2_05/mod.rs 89.84% <100.00%> (-0.52%) ⬇️
clarity/src/vm/analysis/type_checker/v2_1/mod.rs 90.05% <100.00%> (-0.35%) ⬇️
clarity/src/vm/errors.rs 60.52% <ø> (-13.16%) ⬇️
clarity/src/vm/functions/define.rs 98.46% <100.00%> (-0.38%) ⬇️
clarity/src/vm/functions/mod.rs 98.03% <100.00%> (+0.06%) ⬆️
clarity/src/vm/functions/tuples.rs 83.33% <100.00%> (ø)
clarity/src/vm/representations.rs 84.24% <100.00%> (+2.76%) ⬆️
clarity/src/vm/tests/datamaps.rs 82.54% <100.00%> (-16.54%) ⬇️
... and 8 more

... and 285 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 799953e...1396f49. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

[VM] Anemic VM errors in type-checking bindings
1 participant