Skip to content

Commit dabbc1d

Browse files
committed
Allow returntype and where annotations
1 parent 8abd102 commit dabbc1d

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
@@ -3904,3 +3904,25 @@ module ExtendedIsDefined
39043904
@test !$(Expr(:isdefined, GlobalRef(@__MODULE__, :x4), false))
39053905
end
39063906
end
3907+
3908+
# PR# 55040 - Macrocall as function sig
3909+
function callme end
3910+
macro callmemacro(args...)
3911+
Expr(:call, esc(:callme), map(esc, args)...)
3912+
end
3913+
3914+
function @callmemacro(a::Int)
3915+
return 1
3916+
end
3917+
@callmemacro(b::Float64) = 2
3918+
function @callmemacro(a::T, b::T) where T <: Int64
3919+
return 3
3920+
end
3921+
function @callmemacro(a::Int, b::Int, c::Int)::Float64
3922+
return 4
3923+
end
3924+
3925+
@test callme(1) === 1
3926+
@test callme(2.0) === 2
3927+
@test callme(3, 3) === 3
3928+
@test callme(4, 4, 4) === 4.0

0 commit comments

Comments
 (0)