Skip to content

Commit 6b70a37

Browse files
committed
Adjust type tooltips to apply fallback string conversion earlier
We can’t call type->string after expansion completes, since it uses syntax-local-value, so we can’t call it in the thunk that could be invoked after expansion by Check Syntax.
1 parent dfa659c commit 6b70a37

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

hackett-lib/hackett/private/typecheck.rkt

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -329,37 +329,40 @@
329329
; apply-current-subst-in-tooltips is called, however, we evaluate the thunk early and replace the
330330
; property with the new value, improving the information in the tooltips.
331331

332-
(struct deferred-type-in-tooltip (type)
332+
(struct deferred-type-in-tooltip (type string)
333333
#:property prop:procedure
334-
(λ (self) (type->string (apply-current-subst (deferred-type-in-tooltip-type self)))))
334+
(λ (self) (deferred-type-in-tooltip-string self)))
335335

336336
(define/contract (attach-type stx t #:tooltip-src [tooltip-src stx])
337337
(->* [syntax? type?] [#:tooltip-src any/c] syntax?)
338-
(let ([stx* (syntax-property stx ': t)])
338+
(let* ([t* (apply-current-subst t)]
339+
[stx* (syntax-property stx ': t*)])
339340
(if (and (not (syntax-property tooltip-src 'omit-type-tooltip))
340341
(syntax-source tooltip-src)
341342
(syntax-position tooltip-src)
342343
(syntax-span tooltip-src))
343344
(syntax-property
344345
stx* 'mouse-over-tooltips
345-
(syntax-parse tooltip-src
346-
; If it’s a pair, just add the tooltip “on the parens”.
347-
[(_ . _)
348-
(cons
349-
(vector tooltip-src
350-
(sub1 (syntax-position tooltip-src))
351-
(syntax-position tooltip-src)
352-
(deferred-type-in-tooltip t))
353-
(vector tooltip-src
354-
(+ (sub1 (syntax-position tooltip-src)) (sub1 (syntax-span tooltip-src)))
355-
(+ (sub1 (syntax-position tooltip-src)) (syntax-span tooltip-src))
356-
(deferred-type-in-tooltip t)))]
357-
; Otherwise, add the tooltip on the whole region.
358-
[_
359-
(vector tooltip-src
360-
(sub1 (syntax-position tooltip-src))
361-
(+ (sub1 (syntax-position tooltip-src)) (syntax-span tooltip-src))
362-
(deferred-type-in-tooltip t))]))
346+
(let* ([t-str (type->string t*)]
347+
[deferred-tooltip (deferred-type-in-tooltip t* t-str)])
348+
(syntax-parse tooltip-src
349+
; If it’s a pair, just add the tooltip “on the parens”.
350+
[(_ . _)
351+
(cons
352+
(vector tooltip-src
353+
(sub1 (syntax-position tooltip-src))
354+
(syntax-position tooltip-src)
355+
deferred-tooltip)
356+
(vector tooltip-src
357+
(+ (sub1 (syntax-position tooltip-src)) (sub1 (syntax-span tooltip-src)))
358+
(+ (sub1 (syntax-position tooltip-src)) (syntax-span tooltip-src))
359+
deferred-tooltip))]
360+
; Otherwise, add the tooltip on the whole region.
361+
[_
362+
(vector tooltip-src
363+
(sub1 (syntax-position tooltip-src))
364+
(+ (sub1 (syntax-position tooltip-src)) (syntax-span tooltip-src))
365+
deferred-tooltip)])))
363366
stx*)))
364367
(define/contract (attach-expected stx t)
365368
(-> syntax? type? syntax?)
@@ -378,8 +381,8 @@
378381
(recursively-adjust-property
379382
stx 'mouse-over-tooltips
380383
(match-lambda
381-
[(vector a b c (? deferred-type-in-tooltip? d))
382-
(vector a b c (d))]
384+
[(vector a b c (deferred-type-in-tooltip t _))
385+
(vector a b c (type->string (apply-current-subst t)))]
383386
[other other])))
384387

385388
(define/contract (make-typed-var-transformer x t)

0 commit comments

Comments
 (0)