Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type promotion causes stack overflow #94

Open
kaandocal opened this issue Sep 2, 2021 · 3 comments
Open

Type promotion causes stack overflow #94

kaandocal opened this issue Sep 2, 2021 · 3 comments

Comments

@kaandocal
Copy link

kaandocal commented Sep 2, 2021

The following causes a StackOverflowError:

using DynamicPolynomials

promote_type(Any, Polynomial{true,Any})

Here Any can be replaced by various types. Output:

ERROR: StackOverflowError:
Stacktrace:
 [1] promote_result(#unused#::Type, #unused#::Type, #unused#::Type{Any}, #unused#::Type{DynamicPolynomials.Polynomial{true, Any}})
   @ Base ./promotion.jl:247

What happens is that promote_rule(Any, Polynomial{true,Any}) returns Any and promote_rule(Polynomial{true,Any}, Any) returns Polynomial{true,Any}, and promote_result keeps calling itself with the exact same type arguments...

This originally came up trying to run MomentClosure.jl with SymbolicUtils version >= 0.12 (expanding some polynomial expressions). I'm currently trying to figure out the intended semantics behind this and trying to find a fix but I thought it might be useful to point it out :)

@kbarros
Copy link

kbarros commented Oct 9, 2022

Seems related:

using DynamicPolynomials
@ncpolyvar x1
@polyvar x2
promote_type(typeof(x1), typeof(x2)) # stack overflow

@blegat
Copy link
Member

blegat commented Oct 10, 2022

Thanks for reporting these. I would find the root cause of what outputed Polynomial{true,Any}. The coefficient type of a polynomial is not supposed to be Any, e.g., we should be able to call zero on it.
Of course, a StackOverflow is still a but, even if the users does not provide the exptected types.

@kbarros
Copy link

kbarros commented Oct 12, 2022

I think in my case I was accidentally adding commuting and noncommuting polynomial variables,

using DynamicPolynomials
@polyvar x
@ncpolyvar y
x + y

Perhaps it's not the same issue as Polynomial{true,Any}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants