forked from racket/racket
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,8 @@ | |
(contract-out | ||
[struct member-spec ([modifier symbol?] [id symbol?] [sc static-contract?])] | ||
[object/sc ((listof object-member-spec?) . -> . static-contract?)] | ||
[class/sc ((listof member-spec?) boolean? (listof identifier?) (listof identifier?) . -> . static-contract?)])) | ||
[class/sc ((listof member-spec?) boolean? (listof identifier?) (listof identifier?) . -> . static-contract?)] | ||
[instanceof/sc (static-contract? . -> . static-contract?)])) | ||
|
||
|
||
|
||
|
@@ -55,6 +56,27 @@ | |
(define (sc->constraints v f) | ||
(merge-restricts* 'impersonator (map f (member-seq->list (combinator-args v)))))]) | ||
|
||
(struct instanceof-combinator combinator (class) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
#:transparent | ||
#:property prop:combinator-name "instanceof/sc" | ||
#:methods gen:sc | ||
[(define (sc-map v f) | ||
(match v | ||
[(instanceof-combinator args class) | ||
;; FIXME: is this variance correct? | ||
This comment has been minimized.
Sorry, something went wrong.
endobson
|
||
(instanceof-combinator args (f class 'covariant))])) | ||
(define (sc-traverse v f) | ||
(match v | ||
[(instanceof-combinator _ class) | ||
(f class 'covariant) | ||
(void)])) | ||
(define (sc->contract v f) | ||
(instance/sc->contract v f)) | ||
(define (sc->constraints v f) | ||
(match v | ||
[(instanceof-combinator _ class) | ||
(f class)]))]) | ||
|
||
|
||
(define member-seq->list | ||
(match-lambda | ||
|
@@ -81,6 +103,8 @@ | |
(object-combinator (member-seq specs))) | ||
(define (class/sc specs opaque absent-fields absent-methods) | ||
(class-combinator (member-seq specs) opaque absent-fields absent-methods)) | ||
(define (instanceof/sc class) | ||
(instanceof-combinator null class)) | ||
|
||
(define (wrap mod ctc) | ||
(define mod-stx | ||
|
@@ -115,3 +139,7 @@ | |
#`(class/c #,@(if opaque (list '#:opaque) empty) | ||
#,@(map (member-spec->form f) vals) | ||
(absent #,@absent-methods (field #,@absent-fields)))])) | ||
(define (instance/sc->contract v f) | ||
(match v | ||
[(instanceof-combinator _ class) | ||
#`(instanceof/c #,(f class))])) |
Since class is a static contract it should be part of the args field so that it gets printed. Currently I believe that it won't get printed at all and all instanceof-combinators will look the same.