ForwardDiff.jl
ForwardDiff.jl copied to clipboard
promote_rule ambiguity with AbstractIrrational and ForwardDiff.Dual
Just ran into this error:
ERROR: MethodError: promote_rule(::Type{IrrationalConstants.Twoπ}, ::Type{ForwardDiff.Dual{ForwardDiff.Tag{OptimizationReverseDiffExt.OptimizationReverseDiffTag, Float64}, Float64, 12}}) is ambiguous.
Candidates:
promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational, T<:Number}
@ Base irrationals.jl:45
promote_rule(::Type{<:AbstractIrrational}, ::Type{T}) where T<:Real
@ Base irrationals.jl:44
promote_rule(::Type{R}, ::Type{ForwardDiff.Dual{T, V, N}}) where {R<:Real, T, V, N}
@ ForwardDiff C:\Users\...\.julia\packages\ForwardDiff\PcZ48\src\dual.jl:427
Possible fix, define
promote_rule(::Type{R}, ::Type{ForwardDiff.Dual{T, V, N}}) where {R<:AbstractIrrational, T, V, N}
Changing Irrational to AbstractIrrational in this line resolves the problem by defining the missing method. Unless there is a reason not to broaden the typing here, I'll go ahead and open a PR...
I don't see a reason to not switch from Irrational to AbstractIrrational. Very likely there just didn't exist any other implementations of AbstractIrrational when this code was added.
Fixed by #687.