Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #25955, hygiene of arg name of function defined by type #29072

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1682,6 +1682,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