Skip to content

Fix method ambiguities #136

@penelopeysm

Description

@penelopeysm

#130 added Aqua tests. Copilot claims that method ambiguities arise from third-party packages rather than AbstractPPL.

# For now, we skip ambiguities since they come from interactions
# with third-party packages rather than issues in AbstractPPL itself
Aqua.test_all(AbstractPPL; ambiguities=false)

This is untrue. The method ambiguities are (at least partially) AbstractPPL's fault, see below. The ambiguity checks should be enabled and the ambiguities fixed.

IMO the easiest way of fixing these ambiguities is to just remove the get and set methods on VarNames which to me seem like overreach / overuse of multiple dispatch.

"""
get(obj, vn::VarName{sym})
Alias for `(PropertyLens{sym}() ⨟ getoptic(vn))(obj)`.
```
"""
function Base.get(obj, vn::VarName{sym}) where {sym}
return (PropertyLens{sym}() getoptic(vn))(obj)
end

I don't really see a reason why we need to make get(a, @varname(x)) behave like a.x. Firstly, this makes some rather strong assumptions about the structure of the first argument. And even if such a method would be useful, it would be more appropriate to give it a different name rather than overloading Base.get for all types.

4 ambiguities found. To get a list, set `broken = false`.
Ambiguity #1
get(a::DataStructures.MultiDict, args...) @ DataStructures ~/.julia/packages/DataStructures/IrAJn/src/delegate.jl:21
get(obj, vn::AbstractPPL.VarName{sym}) where sym @ AbstractPPL ~/ppl/appl/src/varname.jl:161

Possible fix, define
  get(::DataStructures.MultiDict, ::AbstractPPL.VarName{sym}) where sym

Ambiguity #2
get(a::DataStructures.DefaultDict, args...) @ DataStructures ~/.julia/packages/DataStructures/IrAJn/src/delegate.jl:21
get(obj, vn::AbstractPPL.VarName{sym}) where sym @ AbstractPPL ~/ppl/appl/src/varname.jl:161

Possible fix, define
  get(::DataStructures.DefaultDict, ::AbstractPPL.VarName{sym}) where sym

Ambiguity #3
get(a::DataStructures.DefaultOrderedDict, args...) @ DataStructures ~/.julia/packages/DataStructures/IrAJn/src/delegate.jl:21
get(obj, vn::AbstractPPL.VarName{sym}) where sym @ AbstractPPL ~/ppl/appl/src/varname.jl:161

Possible fix, define
  get(::DataStructures.DefaultOrderedDict, ::AbstractPPL.VarName{sym}) where sym

Ambiguity #4
get(a::DataStructures.DefaultDictBase, args...) @ DataStructures ~/.julia/packages/DataStructures/IrAJn/src/delegate.jl:21
get(obj, vn::AbstractPPL.VarName{sym}) where sym @ AbstractPPL ~/ppl/appl/src/varname.jl:161

Possible fix, define
  get(::DataStructures.DefaultDictBase, ::AbstractPPL.VarName{sym}) where sym

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions