Skip to content

Commit

Permalink
Fix inference of accessors on args in let bindings
Browse files Browse the repository at this point in the history
Fixes #959
  • Loading branch information
eliaslfox committed Jun 15, 2023
1 parent 7819a1f commit f09d9b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/typechecker/define.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2272,8 +2272,14 @@ Returns (VALUES INFERRED-TYPE NODE SUBSTITUTIONS)")
:span (parser:node-source second)
:message "second parameter here"))))))

(let* ((param-tys (loop :for pattern :in (parser:binding-parameters binding)
:collect (tc:make-variable)))
(let* ((param-tys (loop :with args := (tc:function-type-arguments expected-type)
:for pattern :in (parser:binding-parameters binding)

:if args
:collect (car args)
:and :do (setf args (cdr args))
:else
:collect (tc:make-variable)))

(params (loop :for pattern :in (parser:binding-parameters binding)
:for ty :in param-tys
Expand Down
11 changes: 11 additions & 0 deletions tests/struct-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@
(define (f _)
(let ((g (fn (p) (.x p))))
(g (Point 1 2))))")))

;; See gh #959
(deftest test-accessor-on-argument-let-binding ()
(check-coalton-types
"(define-struct (Wrapper :a)
(inner :a))
(declare f (Wrapper :a -> :a))
(define (f x)
(let ((y (.inner x)))
y))"))

0 comments on commit f09d9b5

Please sign in to comment.