Skip to content

Commit

Permalink
fix #25955, hygiene of arg name of function defined by type (`(f::T)(…
Browse files Browse the repository at this point in the history
…...)`) (#29072)
  • Loading branch information
JeffBezanson authored Sep 7, 2018
1 parent cfca833 commit bb7d043
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

;; function definition
(pattern-lambda (function (-$ (call name . argl) (|::| (call name . argl) _t)) body)
(cons 'varlist (safe-llist-positional-args (fix-arglist argl))))
(cons 'varlist (safe-llist-positional-args (fix-arglist (append (self-argname name) argl)))))
(pattern-lambda (function (where callspec . wheres) body)
(let ((others (pattern-expand1 vars-introduced-by-patterns `(function ,callspec ,body))))
(cons 'varlist (append (if (and (pair? others) (eq? (car others) 'varlist))
Expand All @@ -75,7 +75,7 @@
(pattern-lambda (= (call (curly name . sparams) . argl) body)
`(function (call (curly ,name . ,sparams) . ,argl) ,body))
(pattern-lambda (= (-$ (call name . argl) (|::| (call name . argl) _t)) body)
`(function (call ,name ,@argl) ,body))
`(function ,(cadr __) ,body))
(pattern-lambda (= (where callspec . wheres) body)
(cons 'function (cdr __)))

Expand Down Expand Up @@ -257,6 +257,12 @@
;; count escaped argument names as "keywords" to prevent renaming
(safe-llist-positional-args lst #t))))

;; argument name for the function itself given `function (f::T)(...)`, otherwise ()
(define (self-argname name)
(if (and (length= name 3) (eq? (car name) '|::|))
(list (cadr name))
'()))

;; resolve-expansion-vars-with-new-env, but turn on `inarg` once we get inside
;; the formal argument list. `e` in general might be e.g. `(f{T}(x)::T) where T`,
;; and we want `inarg` to be true for the `(x)` part.
Expand Down
14 changes: 14 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,20 @@ end
@test B28593.var.name === :S
@test C28593.var.name === :S

# issue #25955
macro noeffect25955(e)
return e
end

struct foo25955
end

@noeffect25955 function (f::foo25955)()
42
end

@test foo25955()() == 42

# issue #28833
macro m28833(expr)
esc(:(global a28833))
Expand Down

0 comments on commit bb7d043

Please sign in to comment.