Skip to content

Commit 388e2fd

Browse files
committed
Fix racket#1352: Add validation in has-struct-property->sc
When looking up a struct property type, consolidated error handling into a single match expression that properly handles missing types and non- struct-property types instead of causing internal errors. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Closes racket#1352
1 parent df7caae commit 388e2fd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

typed-racket-lib/typed-racket/private/type-contract.rkt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,19 @@
13891389
(define (has-struct-property->sc orig-id)
13901390
;; we can't call syntax-local-value/immediate in has-struct-property case in parse-type
13911391
(define-values (a prop-name) (syntax-local-value/immediate orig-id (λ () (values #t orig-id))))
1392-
(match-define (Struct-Property: _ pred?) (lookup-id-type/lexical prop-name))
1392+
(define pred?
1393+
(match (lookup-id-type/lexical prop-name)
1394+
[(Struct-Property: _ (? values p)) p]
1395+
[(Struct-Property: _ #f)
1396+
(tc-error/fields "struct property has no predicate"
1397+
#:stx orig-id
1398+
"property" (syntax-e orig-id))]
1399+
[#f (tc-error/fields "could not find type for struct property"
1400+
#:stx orig-id
1401+
"property" (syntax-e orig-id))]
1402+
[other (tc-error/fields "expected a Struct-Property type"
1403+
#:stx orig-id
1404+
"given type" other)]))
13931405
;; if original-name is only set when the type is added via require/typed
13941406

13951407
;; the original-name of `prop-name` is its original referece in the unexpanded program.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#;
2+
(exn-pred #rx"struct property has no predicate")
3+
#lang typed/racket
4+
5+
;; Issue #1352: syntax-property: contract violation with Has-Struct-Property
6+
;; Bug in type-contract.rkt has-struct-property->sc function
7+
8+
(require/typed racket/stream
9+
[prop:stream (Struct-Property Any)]
10+
[stream->list (-> (Has-Struct-Property prop:stream) (List Any))])

0 commit comments

Comments
 (0)