Skip to content

Commit 8e4e0e9

Browse files
committed
Make scoped type variables work inside instance declarations
1 parent e1a578a commit 8e4e0e9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

hackett-lib/hackett/private/class.rkt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
(multi-in syntax/parse [class/local-value experimental/template])
77
syntax/id-set
88
syntax/id-table
9-
threading)
9+
threading
10+
11+
hackett/private/util/stx)
1012
(postfix-in - (combine-in racket/base
1113
syntax/id-table))
1214
syntax/parse/define
@@ -204,6 +206,7 @@
204206
(define var+skolem-ids
205207
(map #{cons %1 #`(#%type:rigid-var #,%2)} (attribute var-id-) skolem-ids))
206208
(define bare-ts/skolemized (map #{insts % var+skolem-ids} (attribute bare-t-.expansion)))]
209+
#:with [skolem-id ...] skolem-ids
207210
#:with [constr/skolemized ...] (map #{insts % var+skolem-ids} (attribute constr-/reduced))
208211

209212
; With the skolemized constraints and instance head, we need to synthesize expected types for each
@@ -222,7 +225,11 @@
222225
(map cons (attribute method-id) (attribute impl))))]
223226
#:with [every-impl ...] (for/list ([method-id (in-list all-method-ids)])
224227
(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))))
226233

227234
; Finally, generate some temporaries and expressions needed in the output.
228235
#:with dict-id- (generate-temporary #'class)
@@ -251,11 +258,15 @@
251258
#'(define-syntaxes- [dict-id-] (values))
252259
#'(begin-))
253260
(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 ...])))))
259270
(syntax-property 'disappeared-binding
260271
(~>> (attribute var-id)
261272
(map (λ~>> (internal-definition-context-introduce t-intdef-ctx)

0 commit comments

Comments
 (0)