Skip to content

Commit 2e552a0

Browse files
committed
Allow returntype and where annotations
1 parent 7ad6c86 commit 2e552a0

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/julia-parser.scm

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,20 +1154,20 @@
11541154
(parse-atom s))))
11551155

11561156
(define (parse-def s is-func anon)
1157-
(let ((ex (parse-unary-prefix s)))
1158-
(if (and (pair? ex) (eq? (car ex) 'macrocall))
1159-
ex
1160-
(let* ((sig (if (or (and is-func (reserved-word? ex)) (initial-reserved-word? ex))
1161-
(error (string "invalid name \"" ex "\""))
1162-
(parse-call-chain s ex #f)))
1163-
(decl-sig
1164-
(if (and is-func (eq? (peek-token s) '|::|))
1165-
(begin (take-token s)
1166-
`(|::| ,sig ,(parse-call s)))
1167-
sig)))
1168-
(if (eq? (peek-token s) 'where)
1169-
(parse-where-chain s decl-sig)
1170-
decl-sig)))))
1157+
(let* ((ex (parse-unary-prefix s))
1158+
(sig
1159+
(if (and (pair? ex) (eq? (car ex) 'macrocall)) ex
1160+
(if (or (and is-func (reserved-word? ex)) (initial-reserved-word? ex))
1161+
(error (string "invalid name \"" ex "\""))
1162+
(parse-call-chain s ex #f))))
1163+
(decl-sig
1164+
(if (and is-func (eq? (peek-token s) '|::|))
1165+
(begin (take-token s)
1166+
`(|::| ,sig ,(parse-call s)))
1167+
sig)))
1168+
(if (eq? (peek-token s) 'where)
1169+
(parse-where-chain s decl-sig)
1170+
decl-sig)))
11711171

11721172
(define (disallowed-space-error lno ex t)
11731173
(error (string "space before \"" t "\" not allowed in \""
@@ -1331,14 +1331,12 @@
13311331

13321332
(define (valid-func-sig? paren sig)
13331333
(and (pair? sig)
1334-
(or (eq? (car sig) 'macrocall)
1335-
(eq? (car sig) 'call)
1336-
(eq? (car sig) 'tuple)
1334+
(or (memq (car sig) '(macrocall call tuple))
13371335
(and paren (eq? (car sig) 'block))
13381336
(and paren (eq? (car sig) '...))
13391337
(and (eq? (car sig) '|::|)
13401338
(pair? (cadr sig))
1341-
(eq? (car (cadr sig)) 'call))
1339+
(memq (car (cadr sig)) '(call macrocall)))
13421340
(and (eq? (car sig) 'where)
13431341
(valid-func-sig? paren (cadr sig))))))
13441342

test/syntax.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,3 +3865,25 @@ module UndefGlobal54954
38653865
end
38663866
using .UndefGlobal54954: theglobal54954
38673867
@test Core.get_binding_type(@__MODULE__, :theglobal54954) === Int
3868+
3869+
# PR# 55040 - Macrocall as function sig
3870+
function callme end
3871+
macro callmemacro(args...)
3872+
Expr(:call, esc(:callme), map(esc, args)...)
3873+
end
3874+
3875+
function @callmemacro(a::Int)
3876+
return 1
3877+
end
3878+
@callmemacro(b::Float64) = 2
3879+
function @callmemacro(a::T, b::T) where T <: Int64
3880+
return 3
3881+
end
3882+
function @callmemacro(a::Int, b::Int, c::Int)::Float64
3883+
return 4
3884+
end
3885+
3886+
@test callme(1) === 1
3887+
@test callme(2.0) === 2
3888+
@test callme(3, 3) === 3
3889+
@test callme(4, 4, 4) === 4.0

0 commit comments

Comments
 (0)