diff --git a/core/src/main/java/org/lflang/generator/c/CStateGenerator.java b/core/src/main/java/org/lflang/generator/c/CStateGenerator.java index 225320bfe7..c8686173b6 100644 --- a/core/src/main/java/org/lflang/generator/c/CStateGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CStateGenerator.java @@ -88,8 +88,7 @@ private static String generateModalReset( + "]"; var type = types.getTargetType(instance.tpr.resolveType(ASTUtils.getInferredType(stateVar))); - if (ASTUtils.isOfTimeType(stateVar) - || ASTUtils.isParameterized(stateVar) && !stateVar.getInit().getExprs().isEmpty()) { + if (ASTUtils.isParameterized(stateVar) && !stateVar.getInit().getExprs().isEmpty()) { return CModesGenerator.generateStateResetStructure( instance, modeRef, selfRef, stateVar.getName(), initExpr, type); } else { diff --git a/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf new file mode 100644 index 0000000000..f7d25c97d6 --- /dev/null +++ b/test/C/src/modal_models/ResetStateVariableOfTypeTime.lf @@ -0,0 +1,42 @@ +/** + * Modal Reactor Test. Tests state variable with type time. Model by Edward Lee. + * https://github.com/lf-lang/lingua-franca/issues/1938 + */ +target C { + timeout: 3 s, + fast: true +} + +reactor C { + input trigger: bool + reset state t: time = 0 s + + reaction(trigger) {= + lf_print("t = %ld", self->t); + if (self->t != SEC(0)) { + lf_print("Error: Missing reset"); + } + + self->t = lf_time_logical(); + =} +} + +main reactor { + timer t(0, 1 s) + + initial mode A { + c = new C() + reaction(t) -> reset(B), c.trigger {= + lf_print("In A"); + lf_set(c.trigger, true); + lf_set_mode(B); + =} + } + + mode B { + reaction(t) -> reset(A) {= + lf_print("In B"); + lf_set_mode(A); + =} + } +} diff --git a/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf new file mode 100644 index 0000000000..3e0096e5e0 --- /dev/null +++ b/test/C/src/modal_models/ResetStateVariableWithParameterizedValue.lf @@ -0,0 +1,42 @@ +/** + * Modal Reactor Test. Tests state variable initialized via parameter. Model by Edward Lee. + * https://github.com/lf-lang/lingua-franca/issues/1938 + */ +target C { + timeout: 3 s, + fast: true +} + +reactor C(init: int = 0) { + input trigger: bool + reset state i: int = init + + reaction(trigger) {= + lf_print("i = %d", self->i); + if (self->i != -1) { + lf_print("Error: Missing reset"); + } + + self->i += 10; + =} +} + +main reactor { + timer t(0, 1 s) + + initial mode A { + c = new C(init=-1) + reaction(t) -> reset(B), c.trigger {= + lf_print("In A"); + lf_set(c.trigger, true); + lf_set_mode(B); + =} + } + + mode B { + reaction(t) -> reset(A) {= + lf_print("In B"); + lf_set_mode(A); + =} + } +}