Warning: deprecated syntax .+?

question

#1

Recently, I noticed this warning on my Travis builds Julia v0.6:

WARNING: deprecated syntax “function .+(…)”.
Use “function Base.broadcast(::typeof(+), …)” instead.

Can you please confirm the dot notation is not deprecated?


#2

Yes. .+ no longer exists, neither do any of the . operators. Instead, all . operators are now just calls to broadcast(!)


#3

You mean we have to write broadcast everywhere?


#4

No? Just use .+. You can’t extend "the operator .+" because it doesn’t actually exist though: .+ means broadcast(+,...)


#5

My question is because of these warnings:

https://travis-ci.org/juliohm/ImageQuilting.jl/jobs/249756795#L358


#6

I am just using .+ everywhere and the deprecation warnings are showing up. I am probably doing something wrong somewhere else.


#7

Either you or a package you are using has an overload of .+.


#8

If you read the depwarn carefully, it’s telling you that the function definition have been deprecated, not the use of it.


#9

wild guess: https://github.com/SimonDanisch/FixedSizeArrays.jl/blob/master/src/ops.jl#L42


#10

Thank you all, makes sense, probably one of my dependencies is redefining .+


#11

On the spot @Evizero :slight_smile:


#12

By the way, StaticArrays.jl now provides StaticArrays.FixedSizeArrays which is (mostly) compatible with the old FixedSizeArrays and designed for Julia v0.6. It’s also much nicer since it plays well with the regular StaticArrays types. You might be able to switch over to it without much hassle and get Julia v0.6 compatibility for free.


#13

Btw. I first saw this deprecation warning when I ran some older code where I defined the + function for other types:

v0.6.0> import Base

v0.6.0> Base.+(x::Foo, y::Foo) = ...
WARNING: deprecated syntax "function .+(...)".
Use "function Base.broadcast(::typeof(+), ...)" instead.

Which I fixed with direct import:

v0.6.0> import Base.+

v0.6.0> +(x::Foo, y::Foo) = ...

#14

To extend + without an explicit import, you can do

Base.:+(x, y) = ...

You can also avoid the . in the import statement by using

import Base: +

if you so choose, though of course as you saw, what you have works.