ForwardDiff.jl icon indicating copy to clipboard operation
ForwardDiff.jl copied to clipboard

promote_rule ambiguity with AbstractIrrational and ForwardDiff.Dual

Open ElOceanografo opened this issue 1 year ago • 1 comments

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...

ElOceanografo avatar Mar 01 '24 02:03 ElOceanografo

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.

devmotion avatar Mar 01 '24 09:03 devmotion

Fixed by #687.

devmotion avatar Mar 13 '24 23:03 devmotion