Skip to content

Commit 14da2ad

Browse files
committed
expand deprecation warnings to cover all uses of x.(i) for getfield(x, i); this PR should no longer be a breaking change
1 parent dec609c commit 14da2ad

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

NEWS.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ Breaking changes
6666
instead, a call that cannot be resolved to a single method results
6767
in a `MethodError`. ([#6190])
6868

69-
* The syntax `x.(i::Integer)` for `getfield(x,i)` now means `broadcast(x,i)`.
70-
[`x.(s::Symbol)` still works for `getfield(x,s)`, and `x.(f) = v` works for `setfield!(x, f, v)`, but these are deprecated.]
71-
Use `getfield` or `setfield!` instead ([#15032]).
72-
7369
* `pmap` keyword arguments `err_retry=true` and `err_stop=false` are deprecated.
7470
`pmap` no longer retries or returns `Exception` objects in the result collection.
7571
`pmap(retry(f), c)` or `pmap(@catch(f), c)` can be used instead.

base/deprecated.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,22 +1093,22 @@ end
10931093
#15995
10941094
@deprecate symbol Symbol
10951095

1096-
#15032: Expressions like Base.(:+) now call broadcast. Since there is unlikely
1097-
# to be any legitimate reason to broadcast to a Module (not iterable!),
1098-
# it should be safe to catch this with a deprecation method.
1099-
# Note: this deprecation does not handle method definitions Base.(:+)(...) = ...,
1100-
# which are handled by the deprecate-dotparen function in julia-syntax.scm
1101-
# More generally, expressions like x.(sym) for any Symbol turn into broadcast
1102-
# but should really be getfield, and since you can't broadcast to a symbol
1103-
# using a deprecated broadcast method should be safe. [Unfortunately,
1104-
# we can't catch x.(i::Int) in the same way, because broadcasting to an
1105-
# integer is a valid use of broadcast Most such usages will simply
1106-
# give an error, since x is probably not callable if getfield was intended.]
1096+
#15032: Expressions like Base.(:+) now call broadcast. Since calls
1097+
# to broadcast(x, ::Symbol) are unheard of, and broadcast(x, ::Integer)
1098+
# are unlikely, we can treat these as deprecated getfield calls.
1099+
function broadcast(x::Any, i::Union{Integer,Symbol})
1100+
depwarn("x.(i) is deprecated; use getfield(x, i) instead.", :broadcast)
1101+
getfield(x, i)
1102+
end
1103+
# clearer to be more explicit in the warning for the Module case
11071104
function broadcast(m::Module, s::Symbol)
11081105
depwarn("$m.(:$s) is deprecated; use $m.:$s or getfield($m, :$s) instead.", :broadcast)
11091106
getfield(m, s)
11101107
end
1111-
@deprecate broadcast(x::Any, s::Symbol) getfield(x, s)
1108+
# expressions like f.(3) should still call broadcast for f::Function,
1109+
# and in general broadcast should work for scalar arguments, while
1110+
# getfield is certainly not intended for the case of f::Function.
1111+
broadcast(f::Function, i::Integer) = invoke(broadcast, (Function, Number), f, i)
11121112

11131113
#16167
11141114
macro ccallable(def)

0 commit comments

Comments
 (0)