Skip to content

Commit

Permalink
Merge pull request #1062 from JuliaSymbolics/myb/getprop
Browse files Browse the repository at this point in the history
Add symbolic_getproperty
  • Loading branch information
YingboMa authored Feb 21, 2024
2 parents 5f57198 + f91f71d commit b70f6d7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function decodetyp(typ::TypeT)
end
end

struct Struct
struct Struct <: Real
juliatype::DataType
v::Vector{StructElement}
end
Expand Down Expand Up @@ -108,6 +108,13 @@ function Base.setproperty!(s::Struct, name::Symbol, x)
SymbolicUtils.term(setfield!, s, idx, x; type)
end

function symbolic_getproperty(s, name::Symbol)
SymbolicUtils.term(getfield, s, name, type = Real)
end
function symbolic_getproperty(s::Union{Arr, Num}, name::Symbol)
wrap(symbolic_getproperty(unwrap(s), name))
end

# We cannot precisely derive the type after `getfield` due to SU limitations,
# so give up and just say Real.
SymbolicUtils.promote_symtype(::typeof(getfield), ::Type{<:Struct}, _...) = Real
Expand Down

0 comments on commit b70f6d7

Please sign in to comment.