Skip to content

a slighly uncanny UndefRefError with default-empty SortedSet #969

Open

Description

@exaexa

Hello!

while debugging one certain package (ConstraintTrees.jl) we found the following surprise with 0.19.4:

julia> union(SortedSet(Symbol[:x,:y]),SortedSet(Any[]))
SortedSet{Symbol, Base.Order.ForwardOrdering} with 2 elements:
  :x
  :y

julia> union(SortedSet(Any[]),SortedSet(Symbol[:x,:y]))    # this triggered our tests
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty
   @ ./Base.jl:49 [inlined]
 [2] DataStructures.BalancedTree23{…}(::Val{…}, iterable::Base.Generator{…}, ord::Base.Order.ForwardOrdering, allowdups::Bool)
   @ DataStructures ~/.julia/packages/DataStructures/9m6yb/src/balanced_tree.jl:1053
 [3] SortedSet
   @ ~/.julia/packages/DataStructures/9m6yb/src/sorted_set.jl:82 [inlined]
 [4] packcopy
   @ ~/.julia/packages/DataStructures/9m6yb/src/sorted_set.jl:697 [inlined]
 [5] union(m1::SortedSet{Any, Base.Order.ForwardOrdering}, others::SortedSet{Symbol, Base.Order.ForwardOrdering})
   @ DataStructures ~/.julia/packages/DataStructures/9m6yb/src/sorted_set.jl:360
 [6] top-level scope
   @ REPL[18]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> union(SortedSet(),SortedSet())         # simplest reproducer
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty
   @ ./Base.jl:49 [inlined]
 [2] DataStructures.BalancedTree23{…}(::Val{…}, iterable::Base.Generator{…}, ord::Base.Order.ForwardOrdering, allowdups::Bool)
   @ DataStructures ~/.julia/packages/DataStructures/9m6yb/src/balanced_tree.jl:1053
 [3] SortedSet
   @ ~/.julia/packages/DataStructures/9m6yb/src/sorted_set.jl:82 [inlined]
 [4] union(s1::SortedSet{Any, Base.Order.ForwardOrdering}, others::SortedSet{Any, Base.Order.ForwardOrdering})
   @ DataStructures ~/.julia/packages/DataStructures/9m6yb/src/sorted_set.jl:378
 [5] top-level scope
   @ REPL[19]:1
Some type information was truncated. Use `show(err)` to see complete types.

This was triggered by ConstraintTrees testing code and we can confirm that this "worked" originally in DataStructures 0.18-ish. Notably, other sets (OrderedSet) do not seem to have the issue.

I thought I'd leave a note here just in case this would point to a bigger issue somewhere (UndefRefError sounded scary). I looked at the changelogs but there's no notice of this being undefined behavior or so. I hope I didn't miss some obvious warning somewhere.

(also thanks for making DataStructures! I ❤️ the ordered ones!)

cc @stelmo the original discoverer

Activity

  1. StephenVavasis commented on May 3, 2026

    @StephenVavasis
    Contributor
  2. StephenVavasis commented on May 3, 2026

    @StephenVavasis
    Contributor

    My pull request #970 has failed two of the Github checks. I don't know what these checks do so I don't know how to fix this.

  3. StephenVavasis commented on May 3, 2026

    @StephenVavasis
    Contributor
  4. exaexa commented on May 3, 2026

    @exaexa
    Author

    well see the link: https://app.codecov.io/gh/JuliaCollections/DataStructures.jl/pull/970/indirect-changes
    that condition shortcircuited another condition, so that one is now untested

  5. StephenVavasis commented on May 3, 2026

    @StephenVavasis
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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