Fix type-checking for fields with this

original commit: f82a49be7dbf6e0abb5598179e85a5a06cb0cf2b
This commit is contained in:
Asumu Takikawa 2013-05-23 16:47:06 -04:00
parent 5dd26e30dc
commit d7f6d81607
2 changed files with 14 additions and 6 deletions

View File

@ -528,8 +528,8 @@
(λ (e) (tc-error/expr "Default init value has wrong type"))])
(parameterize ([delay-errors? #f])
(with-lexical-env/extend
(list #'self #'init-args #'extract-arg)
(list (make-Univ) (make-Univ) extract-arg-type)
(list #'extract-arg)
(list extract-arg-type)
(tc-expr form))))]
;; If the type can't be found, it means that there was no
;; expected type or no annotation was provided via (: ...).
@ -566,8 +566,8 @@
(λ (e) (tc-error/expr "Default init value has wrong type"))])
(parameterize ([delay-errors? #f])
(with-lexical-env/extend
(list #'self #'init-args #'extract-arg)
(list (make-Univ) (make-Univ) extract-arg-type)
(list #'extract-arg)
(list extract-arg-type)
(tc-expr form))))]
[else
(tc-error/expr "Init argument ~a has no type annotation"
@ -580,8 +580,7 @@
(#%plain-app local-setter:id obj2:id y:id)))
#:when (free-identifier=? #'x #'y)
#:when (free-identifier=? #'obj1 #'obj2)
(with-lexical-env/extend (list #'self) (list (make-Univ))
(tc-expr form))]
(tc-expr form)]
[_ (void)])))
;; Syntax -> Dict<Symbol, Id> Dict<Symbol, Id>

View File

@ -536,6 +536,15 @@
(: x (Instance (Class)))
(define x (new c%)))
;; test use of `this` in field default
(check-ok
(class: object%
(super-new)
(: x Integer)
(field [x 0])
(: y Integer)
(field [y (get-field x this)])))
;; test different internal/external names
(check-ok
(define c% (class: object% (super-new)