Skip to content

Commit

Permalink
fix JuliaLang#37134, error with macro returning x::T -> y (JuliaLan…
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored and simeonschaub committed Aug 29, 2020
1 parent 25b6231 commit b56c3a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@
(cdr e))))
(else (other e))))

;; given the LHS of e.g. `x::Int -> y`, wrap the signature in `tuple` to normalize
(define (tuple-wrap-arrow-sig e)
(cond ((atom? e) `(tuple ,e))
((eq? (car e) 'where) `(where ,(tuple-wrap-arrow-arglist (cadr e)) ,@(cddr e)))
((eq? (car e) 'tuple) e)
(else `(tuple ,e))))

(define (new-expansion-env-for x env (outermost #f))
(let ((introduced (pattern-expand1 vars-introduced-by-patterns x)))
(if (or (atom? x)
Expand Down Expand Up @@ -370,7 +377,11 @@
(resolve-expansion-vars- x env m parent-scope #f)))
(cdr e))))

((= function ->)
((->)
`(-> ,(resolve-in-function-lhs (tuple-wrap-arrow-sig (cadr e)) env m parent-scope inarg)
,(resolve-expansion-vars-with-new-env (caddr e) env m parent-scope inarg)))

((= function)
(if (and (pair? (cadr e)) (function-def? e))
;; in (kw x 1) inside an arglist, the x isn't actually a kwarg
`(,(car e) ,(resolve-in-function-lhs (cadr e) env m parent-scope inarg)
Expand Down
7 changes: 7 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,13 @@ macro m36272()
end
@test @m36272()(1) == 1

# issue #37134
macro m37134()
:(x :: Int -> 62)
end
@test @m37134()(1) == 62
@test_throws MethodError @m37134()(1.0) == 62

@testset "unary ± and ∓" begin
@test Meta.parse("±x") == Expr(:call, :±, :x)
@test Meta.parse("∓x") == Expr(:call, :, :x)
Expand Down

0 comments on commit b56c3a2

Please sign in to comment.