|
6 | 6 | (multi-in syntax/parse [class/local-value experimental/template]) |
7 | 7 | syntax/id-set |
8 | 8 | syntax/id-table |
9 | | - threading) |
| 9 | + threading |
| 10 | + |
| 11 | + hackett/private/util/stx) |
10 | 12 | (postfix-in - (combine-in racket/base |
11 | 13 | syntax/id-table)) |
12 | 14 | syntax/parse/define |
|
204 | 206 | (define var+skolem-ids |
205 | 207 | (map #{cons %1 #`(#%type:rigid-var #,%2)} (attribute var-id-) skolem-ids)) |
206 | 208 | (define bare-ts/skolemized (map #{insts % var+skolem-ids} (attribute bare-t-.expansion)))] |
| 209 | + #:with [skolem-id ...] skolem-ids |
207 | 210 | #:with [constr/skolemized ...] (map #{insts % var+skolem-ids} (attribute constr-/reduced)) |
208 | 211 |
|
209 | 212 | ; With the skolemized constraints and instance head, we need to synthesize expected types for each |
|
222 | 225 | (map cons (attribute method-id) (attribute impl))))] |
223 | 226 | #:with [every-impl ...] (for/list ([method-id (in-list all-method-ids)]) |
224 | 227 | (let ([provided-impl (free-id-table-ref provided-impls method-id #f)]) |
225 | | - (or provided-impl (free-id-table-ref default-methods method-id)))) |
| 228 | + (if provided-impl |
| 229 | + ; Add the type variable scope to implementations to enable scoped |
| 230 | + ; type variables. |
| 231 | + (internal-definition-context-introduce t-intdef-ctx provided-impl) |
| 232 | + (free-id-table-ref default-methods method-id)))) |
226 | 233 |
|
227 | 234 | ; Finally, generate some temporaries and expressions needed in the output. |
228 | 235 | #:with dict-id- (generate-temporary #'class) |
|
251 | 258 | #'(define-syntaxes- [dict-id-] (values)) |
252 | 259 | #'(begin-)) |
253 | 260 | (define- dict-id- |
254 | | - #,(syntax/loc this-syntax |
255 | | - (:/instance-dictionary |
256 | | - #:methods ([every-method-id : expected-t every-impl] ...) |
257 | | - #:instance-constrs [constr/skolemized ...] |
258 | | - #:superclass-constrs [superclass-constr ...])))) |
| 261 | + ; Keep skolem bindings in scope in expressions to support scoped type variables. |
| 262 | + (let-syntax ([var-id- (make-variable-like-transformer |
| 263 | + (quote-syntax (#%type:rigid-var skolem-id)))] |
| 264 | + ...) |
| 265 | + #,(syntax/loc this-syntax |
| 266 | + (:/instance-dictionary |
| 267 | + #:methods ([every-method-id : expected-t every-impl] ...) |
| 268 | + #:instance-constrs [constr/skolemized ...] |
| 269 | + #:superclass-constrs [superclass-constr ...]))))) |
259 | 270 | (syntax-property 'disappeared-binding |
260 | 271 | (~>> (attribute var-id) |
261 | 272 | (map (λ~>> (internal-definition-context-introduce t-intdef-ctx) |
|
0 commit comments