improve hash-ref error message for non-thunk failure procedure (#2204)

Improve the `hash-ref` error message when the failure result does not
accept zero arguments. (This only changes what the error messages says.)

Example:
```(hash-ref #hash() 'a add1)```

Old message:
```
; add1: arity mismatch;
;  the expected number of arguments does not match the given number
;   expected: 1
;   given: 0
```

New message:
```
; hash-ref: contract violation
;   expected: (-> any)
;   given: #<procedure:add1>
;   argument position: 3rd
```
This commit is contained in:
Ben Greenman 2018-08-05 23:53:49 -04:00 committed by GitHub
parent 3e6846a8d9
commit 2ef8d60cc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -2191,7 +2191,7 @@
(test #t eq? (equal-hash-code l) (equal-hash-code (list 1 2 3)))
(hash-set! h1 l 'ok)
(test 'ok hash-ref h1 l)
(err/rt-test (hash-ref h1 'nonesuch (lambda (x) 'bad-proc)) exn:fail:contract:arity?)
(err/rt-test (hash-ref h1 'nonesuch (lambda (x) 'bad-proc)) exn:fail:contract? "hash-ref")
(test #t hash-has-key? h1 l)
(test #f hash-has-key? h1 (cdr l))
(when hash-ref!

View File

@ -2603,9 +2603,10 @@ static Scheme_Object *hash_failed(int argc, Scheme_Object *argv[])
if (argc == 3) {
v = argv[2];
if (SCHEME_PROCP(v))
if (SCHEME_PROCP(v)) {
scheme_check_proc_arity("hash-ref", 0, 2, argc, argv);
return _scheme_tail_apply(v, 0, NULL);
else
} else
return v;
} else {
scheme_contract_error("hash-ref",