From 09c30fcece0562d4782483ccebd9c4d5487d9b7b Mon Sep 17 00:00:00 2001
From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com>
Date: Thu, 5 Jan 2023 13:27:34 +0100
Subject: [PATCH] Emit better warning. (#2071)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Before
```
✦2 ❯ modcc -t cpu jnml-arbor/SKv3_1.mod
Warnings:
  * jnml-arbor/SKv3_1.mod:(line 1,col 1) Assignments to local variable containing state variables will not be integrated in time
```
After
```
✦2 ❯ modcc -t cpu jnml-arbor/SKv3_1.mod
Warnings:
  * jnml-arbor/SKv3_1.mod:(line 172,col 14) Assignments to local variable containing state variables will not be integrated in time: (rate_m_q = ((m_inf - m_q) / m_tau))
```
---
 modcc/module.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/modcc/module.cpp b/modcc/module.cpp
index dcde114f..c518290f 100644
--- a/modcc/module.cpp
+++ b/modcc/module.cpp
@@ -426,7 +426,7 @@ bool Module::semantic() {
         // Calculate linearity, homogeneity and stochasticity of the statements in the derivative block.
         bool linear = true;
         bool homogeneous = true;
-        bool needs_substitution = false;
+        std::vector<expression_ptr> substitution;
         for (auto& s: solve_body->is_block()->statements()) {
             // loop over declared white noise variables
             if (!white_noise_vars.empty()) {
@@ -447,8 +447,9 @@ bool Module::semantic() {
             }
             if(s->is_assignment() && !state_vars.empty()) {
                 linear_test_result r = linear_test(s->is_assignment()->rhs(), state_vars);
-                if (!s->is_assignment()->lhs()->is_derivative() && !r.is_constant)
-                    needs_substitution = true;
+                if (!s->is_assignment()->lhs()->is_derivative() && !r.is_constant) {
+                    substitution.push_back(s->clone());
+                }
                 linear &= r.is_linear;
                 homogeneous &= r.is_homogeneous;
             }
@@ -472,8 +473,9 @@ bool Module::semantic() {
         std::unique_ptr<SolverVisitorBase> solver;
         switch(solve_expression->method()) {
         case solverMethod::cnexp:
-            if (needs_substitution)
-                warning("Assignments to local variables containing state variables will not be integrated in time");
+            for (const auto& s: substitution) {
+                warning("Assignments to local variable containing state variables will not be integrated in time: " + s->to_string(), s->location());
+            }
             solver = std::make_unique<CnexpSolverVisitor>();
             break;
         case solverMethod::sparse: {
-- 
GitLab