diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 83e1550b28e595..5adb2a9040a8d2 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -1154,20 +1154,20 @@ (parse-atom s)))) (define (parse-def s is-func anon) - (let ((ex (parse-unary-prefix s))) - (if (and (pair? ex) (eq? (car ex) 'macrocall)) - ex - (let* ((sig (if (or (and is-func (reserved-word? ex)) (initial-reserved-word? ex)) - (error (string "invalid name \"" ex "\"")) - (parse-call-chain s ex #f))) - (decl-sig - (if (and is-func (eq? (peek-token s) '|::|)) - (begin (take-token s) - `(|::| ,sig ,(parse-call s))) - sig))) - (if (eq? (peek-token s) 'where) - (parse-where-chain s decl-sig) - decl-sig))))) + (let* ((ex (parse-unary-prefix s)) + (sig + (if (and (pair? ex) (eq? (car ex) 'macrocall)) ex + (if (or (and is-func (reserved-word? ex)) (initial-reserved-word? ex)) + (error (string "invalid name \"" ex "\"")) + (parse-call-chain s ex #f)))) + (decl-sig + (if (and is-func (eq? (peek-token s) '|::|)) + (begin (take-token s) + `(|::| ,sig ,(parse-call s))) + sig))) + (if (eq? (peek-token s) 'where) + (parse-where-chain s decl-sig) + decl-sig))) (define (disallowed-space-error lno ex t) (error (string "space before \"" t "\" not allowed in \"" @@ -1331,14 +1331,12 @@ (define (valid-func-sig? paren sig) (and (pair? sig) - (or (eq? (car sig) 'macrocall) - (eq? (car sig) 'call) - (eq? (car sig) 'tuple) + (or (memq (car sig) '(macrocall call tuple)) (and paren (eq? (car sig) 'block)) (and paren (eq? (car sig) '...)) (and (eq? (car sig) '|::|) (pair? (cadr sig)) - (eq? (car (cadr sig)) 'call)) + (memq (car (cadr sig)) '(call macrocall))) (and (eq? (car sig) 'where) (valid-func-sig? paren (cadr sig)))))) diff --git a/test/syntax.jl b/test/syntax.jl index 2553056fc00b9a..21052f2e6292da 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -3865,3 +3865,25 @@ module UndefGlobal54954 end using .UndefGlobal54954: theglobal54954 @test Core.get_binding_type(@__MODULE__, :theglobal54954) === Int + +# PR# 55040 - Macrocall as function sig +function callme end +macro callmemacro(args...) + Expr(:call, esc(:callme), map(esc, args)...) +end + +function @callmemacro(a::Int) + return 1 +end +@callmemacro(b::Float64) = 2 +function @callmemacro(a::T, b::T) where T <: Int64 + return 3 +end +function @callmemacro(a::Int, b::Int, c::Int)::Float64 + return 4 +end + +@test callme(1) === 1 +@test callme(2.0) === 2 +@test callme(3, 3) === 3 +@test callme(4, 4, 4) === 4.0