Skip to content

Commit

Permalink
fix #45171, keyword sorter location should just be definition line
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 5, 2022
1 parent 902a5c1 commit 89724b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
,(method-def-expr-
name positional-sparams pargl-all
`(block
,@(without-generated prologue)
,@(keep-first linenum? (without-generated prologue))
,(let (;; call mangled(vals..., [rest_kw,] pargs..., [vararg]...)
(ret `(return (call ,mangled
,@(if ordered-defaults keynames vals)
Expand All @@ -562,7 +562,10 @@
,(if (any kwarg? pargl) (gensy) UNUSED)
(call (core kwftype) ,ftype)) ,kw ,@pargl ,@vararg)
`(block
,@(filter linenum? prologue)
,@(let ((lnns (filter linenum? prologue)))
(if (pair? lnns)
(list (car lnns))
'()))
;; nospecialize meta for just positional args
,@(map (lambda (m)
`(meta ,(cadr m) ,@(filter (lambda (v) (not (memq v keynames)))
Expand Down
8 changes: 8 additions & 0 deletions src/utils.scm
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,11 @@
(begin (put! tbl (car xs) i)
(loop (cdr xs) (+ i 1)))))
tbl))

;; keep at most the first element matching a given predicate
(define (keep-first pred lst)
(cond ((null? lst) lst)
((pred (car lst))
(cons (car lst) (filter (lambda (x) (not (pred x))) (cdr lst))))
(else
(cons (car lst) (keep-first pred (cdr lst))))))
13 changes: 13 additions & 0 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ let trace = try
@test trace[1].line == 2
end

# issue #45171
linenum = @__LINE__; function f45171(;kwarg = true)
1
error()
end
let trace = try
f45171()
catch
stacktrace(catch_backtrace())
end
@test trace[3].line == linenum
end

# issue #29695 (see also test for #28442)
let code = """
f29695(c) = g29695(c)
Expand Down

0 comments on commit 89724b5

Please sign in to comment.