Voltage source and ideal capacitor. Incorrect problem

Hello, everyone!
I have some trouble with simple electric circuit: voltage source and custom RC.
If R isn’t equal to zero everything is good, code works.

using ModelingToolkit, DifferentialEquations
import ModelingToolkitStandardLibrary.Electrical, ModelingToolkitStandardLibrary.Blocks
import ModelingToolkit: t_nounits as t, D_nounits as D

@mtkmodel myCapacitor begin
    @parameters begin
        r  = 0.1
        C = 1e-3

    @variables begin

    @extend v, i = oneport = Electrical.OnePort(; i, v)

    @equations begin
        v ~ i*r + v_C
        i ~ C*D(v_C)


@mtkmodel mtkModel begin
    @components begin
        cap = myCapacitor(r=0.5, C=1e-3)
        source = Electrical.Voltage()
        voltage_signal = Blocks.Sine(frequency=5.0)
        ground = Electrical.Ground()
    @equations begin
        connect(source.p, cap.p)
        connect(source.n, cap.n, ground.g)
        connect(voltage_signal.output, source.V)

@mtkbuild model = mtkModel()
problem = ODEProblem(model, [model.cap.v_C => 0.0], (0, 2.0))

solution = solve(problem, Tsit5(), dt = 1e-3, adaptive=false)

but if R is equal to zero I have a warning.

Warning: Instability detected. Aborting

I understand that the problem is now incorrect and voltage cannot be a state variable anymore. I fixed it by replacing the

v ~ i*r + v_C

equation with the

D(v) ~ D(v_C)

But it only works correctly if r=0 because I don’t use “r”.
How can I combine two equations in one?
I tried if/else construction but it doesn’t work.

Thanks in advance for any feedback!

This works fine on the latest versions.

Thank you!
What has changed in the latest version?

A ton. We released a v9 with a bunch of stuff, it would be hard to parse out what it was given this transition period.