Repository navigation
Improve error messages for assert and with-asserts - #1324
NoahStoryM wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Resyntax analyzed 2 files in this pull request and has added suggestions.
| (define pred-parser | ||
| (λ (stx) | ||
| (syntax-parse stx | ||
| #:datum-literals (not/p) | ||
| [(not/p (not/p p)) (pred-parser #'p)] | ||
| [_ stx]))) |
There was a problem hiding this comment.
define-lambda-to-define: The define form supports a shorthand for defining functions (including function-returning functions).
| (define pred-parser | |
| (λ (stx) | |
| (syntax-parse stx | |
| #:datum-literals (not/p) | |
| [(not/p (not/p p)) (pred-parser #'p)] | |
| [_ stx]))) | |
| (define (pred-parser stx) | |
| (syntax-parse stx | |
| #:datum-literals (not/p) | |
| [(not/p (not/p p)) (pred-parser #'p)] | |
| [_ stx])) |
Debugging details
Textual replacement
(line-replacement
#:new-lines
'#(" (define (pred-parser stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [(not/p (not/p p)) (pred-parser #'p)]"
" [_ stx]))")
#:original-lines
'#(" (define pred-parser"
" (λ (stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [(not/p (not/p p)) (pred-parser #'p)]"
" [_ stx])))")
#:start-line 734)Syntactic replacement
(syntax-replacement
#:introduction-scope #<procedure:do-make-syntax-introducer>
#:new-syntax
#<syntax:/home/runner/.local/share/racket/snapshot/pkgs/resyntax/default-recommendations/function-definition-shortcuts.rkt:87:3 (define (pred-parser (ORIGINAL-SPLICE stx)) (ORIGINAL-GAP (stx) (syntax-parse stx #:datum-literals (not/p) ((not/p (not/p p)) (pred-parser (syntax p))) (_ stx))) (ORIGINAL-SPLICE (syntax-parse stx #:datum-literals (not/p) ((not/p (not/p p)) (pred-parser...>
#:original-syntax
#<syntax:typed-racket-lib/typed-racket/base-env/prims.rkt:734:4 (define pred-parser (λ (stx) (syntax-parse stx #:datum-literals (not/p) ((not/p (not/p p)) (pred-parser (syntax p))) (_ stx))))>)| (define assert-parser | ||
| (λ (stx) | ||
| (syntax-parse stx | ||
| #:datum-literals (not/p) | ||
| [[x (not/p p)] #'(p x)] | ||
| [[x p] #'(not (p x))]))) |
There was a problem hiding this comment.
define-lambda-to-define: The define form supports a shorthand for defining functions (including function-returning functions).
| (define assert-parser | |
| (λ (stx) | |
| (syntax-parse stx | |
| #:datum-literals (not/p) | |
| [[x (not/p p)] #'(p x)] | |
| [[x p] #'(not (p x))]))) | |
| (define (assert-parser stx) | |
| (syntax-parse stx | |
| #:datum-literals (not/p) | |
| [[x (not/p p)] #'(p x)] | |
| [[x p] #'(not (p x))])) |
Debugging details
Textual replacement
(line-replacement
#:new-lines
'#(" (define (assert-parser stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [[x (not/p p)] #'(p x)]"
" [[x p] #'(not (p x))]))")
#:original-lines
'#(" (define assert-parser"
" (λ (stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [[x (not/p p)] #'(p x)]"
" [[x p] #'(not (p x))])))")
#:start-line 740)Syntactic replacement
(syntax-replacement
#:introduction-scope #<procedure:do-make-syntax-introducer>
#:new-syntax
#<syntax:/home/runner/.local/share/racket/snapshot/pkgs/resyntax/default-recommendations/function-definition-shortcuts.rkt:87:3 (define (assert-parser (ORIGINAL-SPLICE stx)) (ORIGINAL-GAP (stx) (syntax-parse stx #:datum-literals (not/p) ((x (not/p p)) (syntax (p x))) ((x p) (syntax (not (p x)))))) (ORIGINAL-SPLICE (syntax-parse stx #:datum-literals (not/p) ((x (not/p p)) (syntax...>
#:original-syntax
#<syntax:typed-racket-lib/typed-racket/base-env/prims.rkt:740:4 (define assert-parser (λ (stx) (syntax-parse stx #:datum-literals (not/p) ((x (not/p p)) (syntax (p x))) ((x p) (syntax (not (p x)))))))>)There was a problem hiding this comment.
Resyntax analyzed 2 files in this pull request and found no issues.
|
Coming back to this after quite a while, I like the error message improvements but I don't think we should have a DSL for assertions; they should stay regular Racket expressions. |
|
I actually think that such DSLs are a good thing especially in this day and age. |
…tics Remove the assertion-specific not/p grammar while retaining source-aware errors. Report the failed value in with-asserts without evaluating predicate expressions again, and document the contract exceptions.
Cover ordinary locally bound predicate constructors, failure messages, evaluation order, short-circuiting, and multiple results. Check positive, negative, truthiness, and sequential occurrence refinements over union-typed arguments.
assert and with-asserts.assert and with-asserts
There was a problem hiding this comment.
Resyntax analyzed 5 files in this pull request and found no issues.
|
Thanks for revisiting this! I've narrowed this PR to the error-message improvements and removed the assertion-specific |
Assertion failures now identify the source assertion and the failing value.
assertalso includes the predicate name when available;with-assertsidentifiesthe first failed clause. Predicates remain ordinary Racket expressions, and this
PR does not introduce a predicate DSL.
The changes preserve evaluation order, single evaluation of predicate expressions,
short-circuiting, multiple body results, and occurrence typing. Assertion failures
use
exn:fail:contract, as produced byraise-arguments-error.Tests cover diagnostics and runtime behavior, plus positive, negative, truthiness,
and sequential refinements over union-typed arguments.
Validation: 10 assertion test cases, 6 existing primitive test cases, and 5 targeted
integration cases pass on both the original PR baseline with Racket 8.8 CS and the
latest upstream with Racket 9.3.0.10 CS. The updated Utilities chapter builds and its
examples run. The full CI suite has not been run locally.