Skip to content

Cannot convert an object of type SymbolicUtils.BasicSymbolic{Number} to an object of type Complex{Num} #1661

@songjhaha

Description

@songjhaha

In Julia 1.11

using Symbolics
@variables t::Real x::Number y::Complex z(t)

got error:

julia>  @variables t::Real x::Number y::Complex z(t)
ERROR: MethodError: Cannot `convert` an object of type SymbolicUtils.BasicSymbolic{Number} to an object of type Complex{Num}
The function `convert` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  (::Type{Complex{T}} where T<:Real)(::Any, ::Any)
   @ Base complex.jl:14
  convert(::Type{T}, ::T) where T<:Number
   @ Base number.jl:6
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:126
  ...

Stacktrace:
 [1] setindex!(A::Vector{Complex{Num}}, x::SymbolicUtils.BasicSymbolic{Number}, i::Int64)
   @ Base .\array.jl:987
 [2] (::Base.var"#129#130"{Vector{Complex{Num}}})(i::Int64, v::SymbolicUtils.BasicSymbolic{Number})
   @ Base .\array.jl:408
 [3] afoldl(::Base.var"#129#130"{Vector{…}}, ::Int64, ::Num, ::SymbolicUtils.BasicSymbolic{Number}, ::Complex{Num}, ::Num)
   @ Base .\operators.jl:554
 [4] getindex(::Type{Complex{Num}}, ::Num, ::SymbolicUtils.BasicSymbolic{Number}, ::Complex{Num}, ::Num)
   @ Base .\array.jl:407
 [5] vect(::Num, ::Vararg{Any})
   @ Base .\array.jl:185
 [6] top-level scope
   @ REPL[4]:1
Some type information was truncated. Use `show(err)` to see complete types.

Julia 1.10 could run this code,but could get same error if we reverse variables list like @variables y::Complex x::Number t::Real z(t)

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