diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 254d622dd7e9e..ca5b0e13174db 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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) @@ -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))) diff --git a/src/utils.scm b/src/utils.scm index 7be6b2999a90c..97464b9a14e5a 100644 --- a/src/utils.scm +++ b/src/utils.scm @@ -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)))))) diff --git a/test/backtrace.jl b/test/backtrace.jl index 35b607137a5c2..c0abad5146b39 100644 --- a/test/backtrace.jl +++ b/test/backtrace.jl @@ -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)