Fix infer-self-type
for depth overriden methods
When an overriden method implements a subtype of the superclass type, sometimes the typechecker gets confused what the type should be in the resulting class type. original commit: 85b70aef7f66f0e0c8716fca716d1e38478bf763
This commit is contained in:
parent
569b55bf69
commit
088a59038a
|
@ -1350,17 +1350,23 @@
|
|||
[(Class: _ inits fields publics augments init-rest)
|
||||
(values inits fields publics augments init-rest)]
|
||||
[_ (values #f #f #f #f #f)]))
|
||||
(define-values (inits fields publics pubments init-rest-name)
|
||||
(define-values (inits fields publics pubments overrides init-rest-name)
|
||||
(values (hash-ref parse-info 'init-internals)
|
||||
(hash-ref parse-info 'field-internals)
|
||||
(hash-ref parse-info 'public-internals)
|
||||
(hash-ref parse-info 'pubment-internals)
|
||||
(hash-ref parse-info 'override-internals)
|
||||
(hash-ref parse-info 'init-rest-name)))
|
||||
(define init-types (make-inits inits super-inits expected-inits))
|
||||
(define field-types (make-type-dict fields super-fields expected-fields Univ))
|
||||
(define public-types (make-type-dict (append publics pubments)
|
||||
|
||||
;; This should consider all new public methods, but should also look at
|
||||
;; overrides to ensure that if an overriden method has a more specific type
|
||||
;; (via depth subtyping) then it's accounted for.
|
||||
(define public-types (make-type-dict (append publics pubments overrides)
|
||||
super-methods expected-publics
|
||||
top-func))
|
||||
|
||||
(define augment-types (make-type-dict
|
||||
pubments super-augments expected-augments top-func
|
||||
#:annotations-from augment-annotation-table))
|
||||
|
|
|
@ -1667,4 +1667,20 @@
|
|||
(super-new)
|
||||
(define/override (get-this) this)))
|
||||
(void))
|
||||
-Void]))
|
||||
-Void]
|
||||
;; Test that depth subtyping is accounted for with overriden methods
|
||||
[tc-e (let ()
|
||||
(define-type-alias B% (Class [n (-> Real)]))
|
||||
(: b% B%)
|
||||
(define b%
|
||||
(class object%
|
||||
(super-new)
|
||||
(define/public (n) 123.456)))
|
||||
(define-type-alias C% (Class #:implements B% [n (-> Integer)]))
|
||||
(: c% C%)
|
||||
(define c%
|
||||
(class b%
|
||||
(super-new)
|
||||
(override* [n (lambda () 5)])))
|
||||
(send (new c%) n))
|
||||
-Integer]))
|
||||
|
|
Loading…
Reference in New Issue
Block a user