From 4df4c2506edacde4dcb49cce3d6301ec25d588d1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 21 Jun 2017 00:07:30 -0700 Subject: [PATCH] deprecate syntax `1.+`. fixes #19089 --- NEWS.md | 2 ++ base/sparse/linalg.jl | 2 +- src/julia-parser.scm | 8 +++++++- test/arrayops.jl | 38 +++++++++++++++++------------------ test/linalg/dense.jl | 4 ++-- test/parse.jl | 6 +++--- test/perf/kernel/laplace.jl | 6 +++--- test/perf/kernel/raytracer.jl | 2 +- test/perf/micro/perf.jl | 2 +- test/perf/spell/perf.jl | 2 +- test/ranges.jl | 4 ++-- 11 files changed, 42 insertions(+), 34 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6bcc2fc706f35b..13ea009397296c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ New language features Language changes ---------------- + * The syntax `1.+2` is deprecated, since it is ambiguous: it could mean either + `1 .+ 2` (the current meaning) or `1. + 2` ([#19089]). Breaking changes ---------------- diff --git a/base/sparse/linalg.jl b/base/sparse/linalg.jl index 8f0463449fef26..2a6c0378382ef3 100644 --- a/base/sparse/linalg.jl +++ b/base/sparse/linalg.jl @@ -611,7 +611,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A)))) end end end - scale!(X, 1./n) + scale!(X, 1 ./ n) iter = 0 local est diff --git a/src/julia-parser.scm b/src/julia-parser.scm index e15e23d7fb0167..e8c5998ed69e0c 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -306,7 +306,13 @@ (if (eqv? (peek-char port) #\.) (begin (read-char port) (if (dot-opchar? (peek-char port)) - (io.ungetc port #\.) + (begin + (if (not (eqv? (peek-char port) #\.)) + (let ((num (get-output-string str))) + (syntax-deprecation port + (string num #\. (peek-char port)) + (string num " ." (peek-char port))))) + (io.ungetc port #\.)) (begin (write-char #\. str) (read-digs #f #t) (if (eq? pred char-hex?) diff --git a/test/arrayops.jl b/test/arrayops.jl index 56a06f325628aa..92f69a6a8f2ac7 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -16,31 +16,31 @@ using TestHelpers.OAs @test length((1,)) == 1 @test length((1,2)) == 2 - @test isequal(1.+[1,2,3], [2,3,4]) - @test isequal([1,2,3].+1, [2,3,4]) - @test isequal(1.-[1,2,3], [0,-1,-2]) - @test isequal([1,2,3].-1, [0,1,2]) + @test isequal(1 .+ [1,2,3], [2,3,4]) + @test isequal([1,2,3] .+ 1, [2,3,4]) + @test isequal(1 .- [1,2,3], [0,-1,-2]) + @test isequal([1,2,3] .- 1, [0,1,2]) @test isequal(5*[1,2,3], [5,10,15]) @test isequal([1,2,3]*5, [5,10,15]) - @test isequal(1./[1,2,5], [1.0,0.5,0.2]) + @test isequal(1 ./ [1,2,5], [1.0,0.5,0.2]) @test isequal([1,2,3]/5, [0.2,0.4,0.6]) - @test isequal(2.%[1,2,3], [0,0,2]) - @test isequal([1,2,3].%2, [1,0,1]) - @test isequal(2.÷[1,2,3], [2,1,0]) - @test isequal([1,2,3].÷2, [0,1,1]) - @test isequal(-2.%[1,2,3], [0,0,-2]) + @test isequal(2 .% [1,2,3], [0,0,2]) + @test isequal([1,2,3] .% 2, [1,0,1]) + @test isequal(2 .÷ [1,2,3], [2,1,0]) + @test isequal([1,2,3] .÷ 2, [0,1,1]) + @test isequal(-2 .% [1,2,3], [0,0,-2]) @test isequal([-1,-2,-3].%2, [-1,0,-1]) - @test isequal(-2.÷[1,2,3], [-2,-1,0]) - @test isequal([-1,-2,-3].÷2, [0,-1,-1]) - - @test isequal(1.<<[1,2,5], [2,4,32]) - @test isequal(128.>>[1,2,5], [64,32,4]) - @test isequal(2.>>1, 1) - @test isequal(1.<<1, 2) - @test isequal([1,2,5].<<[1,2,5], [2,8,160]) - @test isequal([10,20,50].>>[1,2,5], [5,5,1]) + @test isequal(-2 .÷ [1,2,3], [-2,-1,0]) + @test isequal([-1,-2,-3] .÷ 2, [0,-1,-1]) + + @test isequal(1 .<< [1,2,5], [2,4,32]) + @test isequal(128 .>> [1,2,5], [64,32,4]) + @test isequal(2 .>> 1, 1) + @test isequal(1 .<< 1, 2) + @test isequal([1,2,5] .<< [1,2,5], [2,8,160]) + @test isequal([10,20,50] .>> [1,2,5], [5,5,1]) a = ones(2,2) diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index 74d26f0601c939..501acb6f9d2b23 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -278,7 +278,7 @@ end # Against vectorized versions @test norm(x,-Inf) ≈ minimum(abs.(x)) - @test norm(x,-1) ≈ inv(sum(1./abs.(x))) + @test norm(x,-1) ≈ inv(sum(1 ./ abs.(x))) @test norm(x,0) ≈ sum(x .!= 0) @test norm(x,1) ≈ sum(abs.(x)) @test norm(x) ≈ sqrt(sum(abs2.(x))) @@ -362,7 +362,7 @@ end ## Issue related tests @testset "issue #1447" begin - A = [1.+0.0im 0; 0 1] + A = [1.0+0.0im 0; 0 1] B = pinv(A) for i = 1:4 @test A[i] ≈ B[i] diff --git a/test/parse.jl b/test/parse.jl index d07c558179be9a..07b9c93bdab958 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -21,9 +21,9 @@ end # issue #9684 let undot(op) = Symbol(string(op)[2:end]) - for (ex1, ex2) in [("5.≠x", "5.!=x"), - ("5.≥x", "5.>=x"), - ("5.≤x", "5.<=x")] + for (ex1, ex2) in [("5 .≠ x", "5 .!= x"), + ("5 .≥ x", "5 .>= x"), + ("5 .≤ x", "5 .<= x")] ex1 = parse(ex1); ex2 = parse(ex2) @test ex1.head === :call && (ex1.head === ex2.head) @test ex1.args[2] === 5 && ex2.args[2] === 5 diff --git a/test/perf/kernel/laplace.jl b/test/perf/kernel/laplace.jl index 010adc2bd43e03..9c8365872a18cd 100644 --- a/test/perf/kernel/laplace.jl +++ b/test/perf/kernel/laplace.jl @@ -5,7 +5,7 @@ function laplace_iter_devec(u, dx2, dy2, Niter, N) for iter = 1:Niter for i = 2:N-1 for j = 2:N-1 - uout[i,j] = ( (u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1./(2*(dx2+dy2))) + uout[i,j] = ( (u[i-1,j]+u[i+1,j])*dy2 + (u[i,j-1]+u[i,j+1])*dx2 ) * (1 ./ (2*(dx2+dy2))) end end u, uout = uout, u @@ -24,7 +24,7 @@ end function laplace_iter_vec(u, dx2, dy2, Niter, N) for i = 1:Niter - u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1./ (2*(dx2+dy2))) + u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1,1:N-2] + u[2:N-1, 3:N])*dx2) * (1 ./ (2*(dx2+dy2))) end return u end @@ -40,7 +40,7 @@ end function laplace_iter_vec_sub(u, dx2, dy2, Niter, N) for i = 1:Niter - u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1,1:N-2) + view(u,2:N-1, 3:N))*dx2) * (1./ (2*(dx2+dy2))) + u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1,1:N-2) + view(u,2:N-1, 3:N))*dx2) * (1 ./ (2*(dx2+dy2))) end return u end diff --git a/test/perf/kernel/raytracer.jl b/test/perf/kernel/raytracer.jl index 78c1a131f95a5b..b3451222f44024 100644 --- a/test/perf/kernel/raytracer.jl +++ b/test/perf/kernel/raytracer.jl @@ -129,7 +129,7 @@ function Raytracer(levels, n, ss) g = 0. for dx in 0:1:(ss-1) for dy in 0:1:(ss-1) - d = Vec(x+dx*1./ss-n/2., y+dy*1./ss-n/2., n*1.0) + d = Vec(x+dx*1.0/ss-n/2.0, y+dy*1.0/ss-n/2.0, n*1.0) ray = Ray(Vec(0., 0., -4.0), unitize(d)) g += ray_trace(light, ray, scene) end diff --git a/test/perf/micro/perf.jl b/test/perf/micro/perf.jl index 5f10f1023b3cfa..e5686d98d079de 100644 --- a/test/perf/micro/perf.jl +++ b/test/perf/micro/perf.jl @@ -101,7 +101,7 @@ function pisumvec() s = 0.0 a = [1:10000] for j = 1:500 - s = sum(1./(a.^2)) + s = sum(1 ./ (a.^2)) end s end diff --git a/test/perf/spell/perf.jl b/test/perf/spell/perf.jl index c5a8dee8dc028b..4e1bc813f4a228 100644 --- a/test/perf/spell/perf.jl +++ b/test/perf/spell/perf.jl @@ -92,7 +92,7 @@ function spelltest(tests; bias=0, verbose=false) end end - return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100.*bad/n), + return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100. * bad/n), "unknown"=>unknown, "secs"=>toc()) end diff --git a/test/ranges.jl b/test/ranges.jl index 30b87be782b729..4db7c8cab32ac3 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -922,8 +922,8 @@ end @testset "logspace" begin n = 10; a = 2; b = 4 # test default values; n = 50, base = 10 - @test logspace(a, b) == logspace(a, b, 50) == 10.^linspace(a, b, 50) - @test logspace(a, b, n) == 10.^linspace(a, b, n) + @test logspace(a, b) == logspace(a, b, 50) == 10 .^ linspace(a, b, 50) + @test logspace(a, b, n) == 10 .^ linspace(a, b, n) for base in (10, 2, e) @test logspace(a, b, base=base) == logspace(a, b, 50, base=base) == base.^linspace(a, b, 50) @test logspace(a, b, n, base=base) == base.^linspace(a, b, n)