Suzhou-Tongyuan / ObjectOriented.jl

Conventional object-oriented programming in Julia without breaking Julia's core design ideas
MIT License
88 stars 6 forks source link

circular reference hangs `getproperty_fallback` #12

Closed t-bltg closed 8 months ago

t-bltg commented 8 months ago

I have a complicated example where accessing a missing property of an object with nested circular references hangs indefinitely.

I narrowed this down to https://github.com/Suzhou-Tongyuan/ObjectOriented.jl/blob/d2ac0144d94c94428c8bc4755b1aede177cabe36/src/runtime.jl#L67

One solution would be to limit the repr output:

function getproperty_fallback(self::T, name) where T
    rself = repr(self; context = (:limit => true, :compact => true))
    error("unknown property '$name' for object '$rself' of type '$T'")
end

Another would be to avoid displaying the object in the error message, and only display the type:

function getproperty_fallback(_::T, name) where T
    error("unknown property '$name' for object of type '$T'")
end

Unfortunately I couldn't come up with a reduced mwe for adding a regression test in CI, or as a simple reproducer.

thautwarm commented 8 months ago

Thanks for your PR. The limit repr seems not a solid solution. Only showing type in the error looks fine to me, consider this:

julia> struct S
       end

julia> S().a
ERROR: type S has no field a
t-bltg commented 8 months ago

Thanks for merging !