Skip to content

Commit

Permalink
more consistent expansion for veneer predicates/converters
Browse files Browse the repository at this point in the history
In particular, do not *include* the annotation's predicate if
unchecked, which means the predicate is neither evaluated nor even
expanded.  I'm not sure whether this is intended, but it seems
consistent with how other forms behave.  This may deserve more
discussion at #419.
  • Loading branch information
usaoc committed Feb 18, 2024
1 parent d81a298 commit 5b01412
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 19 deletions.
45 changes: 26 additions & 19 deletions rhombus/private/veneer.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
#f
dot-provider-rhss parent-dot-providers
#`(name name-extends tail-name
#,(and (syntax-e #'check?) #'name?) name-convert
name?/checked name-convert
constructor-name name-instance name-ref name-of
#f #f dot-provider-name
indirect-static-infos
Expand Down Expand Up @@ -390,29 +390,36 @@
(list
(if converter?
#`(define name-convert
(let ([name? ann.predicate])
(lambda (v who)
#,(cond
[(syntax-e #'check?)
#`(if (and #,(if super? #`(#,super? v) #t)
(name? v))
(if who
v
(lambda () v))
(if who
(raise-binding-failure who "argument" v '#,all-ann-str)
#f))]
[else
#`(if who
v
(lambda () v))]))))
#,(cond
[(syntax-e #'check?)
#`(let ([name? ann.predicate])
(let ([name? (lambda (v)
#,(if super?
#`(and (#,super? v)
(name? v))
#`(name? v)))])
(lambda (v who)
(if (name? v)
(if who
v
(lambda () v))
(if who
(raise-binding-failure who "argument" v '#,all-ann-str)
#f)))))]
[else
#`(lambda (v who)
(if who
v
(lambda () v)))]))
#`(define name?
#,(cond
[(syntax-e #'check?)
#`(let ([name? ann.predicate])
(let ([name? (lambda (v)
(and #,(if super? #`(#,super? v) #t)
(name? v)))])
#,(if super?
#`(and (#,super? v)
(name? v))
#`(name? v)))])
(case-lambda
[(v) (name? v)]
[(v who) (unless (name? v)
Expand Down
55 changes: 55 additions & 0 deletions rhombus/tests/veneer.rhm
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,58 @@ check:
check:
IdSet2("oops") ~is "oops"
"oops" :: IdSet2 ~is "oops"

// check evaluation/expansion of annotations in veneers
check:
veneer Unchecked(this :~ Any.of(error("should not get here")))
~completes

check:
veneer Unchecked(this :~ Any.of(error("should not get here"))):
converter
~completes

check:
veneer Checked(this :: Any.of(error("should get here")))
#void
~throws "should get here"

check:
veneer Checked(this :: Any.of(error("should get here"))):
converter
#void
~throws "should get here"

check:
~eval
import rhombus/meta open
expr.macro 'meta_error($msg)':
syntax_meta.error(msg)
veneer Unchecked(this :~ Any.of(meta_error("should not get here")))
~completes

check:
~eval
import rhombus/meta open
expr.macro 'meta_error($msg)':
syntax_meta.error(msg)
veneer Unchecked(this :~ Any.of(meta_error("should not get here"))):
converter
~completes

check:
~eval
import rhombus/meta open
expr.macro 'meta_error($msg)':
syntax_meta.error(msg)
veneer Checked(this :: Any.of(meta_error("should get here")))
~throws "should get here"

check:
~eval
import rhombus/meta open
expr.macro 'meta_error($msg)':
syntax_meta.error(msg)
veneer Checked(this :: Any.of(meta_error("should get here"))):
converter
~throws "should get here"

0 comments on commit 5b01412

Please sign in to comment.