Skip to content

Commit f32ffbc

Browse files
vtjnashElOceanografo
authored andcommitted
lowering: remove incorrect comprehension eta reduction (JuliaLang#39139)
But keep it for `[f(_) for _ in x]`, since that would now triggers a deprecation error (which was previously incorrectly missing for _). Fixes JuliaLang#18621
1 parent 2c08099 commit f32ffbc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/julia-syntax.scm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,12 +1714,14 @@
17141714
((eq? expr argname)
17151715
;; use `identity` for x->x
17161716
`(top identity))
1717+
;; TODO: deprecate this (#18621):
17171718
((and (null? splat)
17181719
(length= expr 3) (eq? (car expr) 'call)
17191720
(eq? (caddr expr) argname)
1721+
(underscore-symbol? argname)
17201722
(not (dotop-named? (cadr expr)))
17211723
(not (expr-contains-eq argname (cadr expr))))
1722-
;; eta reduce `x->f(x)` => `f`
1724+
;; eta reduce `_->f(_)` => `f`
17231725
(cadr expr))
17241726
(else
17251727
(let ((expr (cond ((and flat (pair? expr) (eq? (car expr) 'generator))

test/core.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7541,3 +7541,12 @@ const RedefineVarargN{N} = Tuple{Vararg{RedefineVararg, N}}
75417541

75427542
# NTuples with non-types
75437543
@test NTuple{3, 2} == Tuple{2, 2, 2}
7544+
7545+
# issue #18621
7546+
function f18621()
7547+
g = (k(i) for i in 1:5)
7548+
k = identity
7549+
return collect(g)
7550+
end
7551+
@test f18621() == 1:5
7552+
@test [_ for _ in 1:5] == 1:5

0 commit comments

Comments
 (0)