diff --git a/src/macroexpand.scm b/src/macroexpand.scm index b7b3e78c994ce..ea341c928eb18 100644 --- a/src/macroexpand.scm +++ b/src/macroexpand.scm @@ -59,9 +59,12 @@ ;; function definition (pattern-lambda (function (-$ (call name . argl) (|::| (call name . argl) _t)) body) (cons 'varlist (safe-llist-positional-args (fix-arglist argl)))) - (pattern-lambda (function (where (-$ (call name . argl) (|::| (call name . argl) _t)) . wheres) body) - (cons 'varlist (append (safe-llist-positional-args (fix-arglist argl)) - (typevar-names wheres)))) + (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)) + (cdr others) + '()) + (typevar-names wheres))))) (pattern-lambda (function (tuple . args) body) `(-> (tuple ,@args) ,body)) @@ -71,7 +74,7 @@ `(function (call (curly ,name . ,sparams) . ,argl) ,body)) (pattern-lambda (= (-$ (call name . argl) (|::| (call name . argl) _t)) body) `(function (call ,name ,@argl) ,body)) - (pattern-lambda (= (where (-$ (call name . argl) (|::| (call name . argl) _t)) . wheres) body) + (pattern-lambda (= (where callspec . wheres) body) (cons 'function (cdr __))) ;; anonymous function @@ -150,14 +153,14 @@ (pattern-lambda (function (-$ (call name . argl) (|::| (call name . argl) _t)) body) (cons 'varlist (safe-llist-keyword-args (fix-arglist argl)))) - (pattern-lambda (function (where (-$ (call name . argl) (|::| (call name . argl) _t)) . wheres) body) - (cons 'varlist (safe-llist-keyword-args (fix-arglist argl)))) + (pattern-lambda (function (where callspec . wheres) body) + `(function ,callspec ,body)) (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)) - (pattern-lambda (= (where (-$ (call name . argl) (|::| (call name . argl) _t)) . wheres) body) + (pattern-lambda (= (where callspec . wheres) body) (cons 'function (cdr __))) )) diff --git a/test/syntax.jl b/test/syntax.jl index 7cdbc55178c67..8b81d16638b23 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -1489,3 +1489,15 @@ let val(::Type{Val{X}}) where {X} = X, f end @test val(first(methods(f())).sig.parameters[2])(21) == 42 end + +# issue #27807 +module A27807 +macro m() + quote + function foo(x::T, y::S) where T<:Number where S<:Number + return one(T), zero(S) + end + end +end +end +@test A27807.@m()(1,1.0) === (1, 0.0)