Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into b/611-migrate-to-ex…
Browse files Browse the repository at this point in the history
…proniconjl-v08-from-unityperjl
  • Loading branch information
bowenszhu committed Sep 16, 2024
2 parents d924da7 + b959fd8 commit 36d28cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymbolicUtils"
uuid = "d1185830-fcd6-423d-90d6-eec64667417b"
authors = ["Shashi Gowda"]
version = "3.6.0"
version = "3.7.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
12 changes: 10 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ promote_symtype(f, Ts...) = Any
#### Function-like variables
#---------------------------

struct FnType{X<:Tuple,Y} end
struct FnType{X<:Tuple,Y,Z} end

(f::Symbolic{<:FnType})(args...) = _Term(promote_symtype(f, symtype.(args)...), f, [args...])

Expand Down Expand Up @@ -1128,8 +1128,16 @@ function _name_type(x)
lhs, rhs = x.args[1:2]
if lhs isa Expr && lhs.head === :call
# e.g. f(::Real)::Unreal
if lhs.args[1] isa Expr
func_name_and_type = _name_type(lhs.args[1])
name = func_name_and_type.name
functype = func_name_and_type.type
else
name = lhs.args[1]
functype = Nothing
end
type = map(x->_name_type(x).type, lhs.args[2:end])
return (name=lhs.args[1], type=:($FnType{Tuple{$(type...)}, $rhs}))
return (name=name, type=:($FnType{Tuple{$(type...)}, $rhs, $functype}))
else
return (name=lhs, type=rhs)
end
Expand Down
19 changes: 18 additions & 1 deletion test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Test

@testset "@syms" begin
let
@syms a b::Float64 f(::Real) g(p, h(q::Real))::Int
@syms a b::Float64 f(::Real) g(p, h(q::Real))::Int

@test issym(a) && symtype(a) == Number
@test a.impl.name === :a
Expand All @@ -16,9 +16,11 @@ using Test

@test issym(f)
@test f.impl.name === :f
@test symtype(f) == FnType{Tuple{Real}, Number, Nothing}

@test issym(g)
@test g.impl.name === :g
@test symtype(g) == FnType{Tuple{Number, FnType{Tuple{Real}, Number, Nothing}}, Int, Nothing}

@test isterm(f(b))
@test symtype(f(b)) === Number
Expand All @@ -32,6 +34,21 @@ using Test
# issue #91
@syms h(a,b,c)
@test isequal(h(1,2,3), h(1,2,3))

@syms (f::typeof(max))(::Real, ::AbstractFloat)::Number a::Real
@test issym(f)
@test f.name == :f
@test symtype(f) == FnType{Tuple{Real, AbstractFloat}, Number, typeof(max)}
@test isterm(f(a, b))
@test symtype(f(a, b)) == Number

@syms g(p, (h::typeof(identity))(q::Real)::Number)::Number
@test issym(g)
@test g.name == :g
@test symtype(g) == FnType{Tuple{Number, FnType{Tuple{Real}, Number, typeof(identity)}}, Number, Nothing}
@test_throws "not a subtype of" g(a, f)
@syms (f::typeof(identity))(::Real)::Number
@test symtype(g(a, f)) == Number
end
end

Expand Down

0 comments on commit 36d28cc

Please sign in to comment.