Skip to content

String variable assignment/comparison silently fails (returns 0 instead of the string value; comparison inside IF() fails with "Unknown fluid" error) #4

Description

@hamstercao

Summary

String-typed variables (name$) do not appear to work correctly in CoolSolve, in three related ways:

Copying one string variable's value into another (var2$ = var1$) does not propagate the string — the destination variable resolves to 0 instead of the source string, with no error raised.
Comparing a string variable against a string literal inside IF() (IF(var$ = 'literal', a, b)) fails at solve time with an EvaluationError: Unknown fluid: — even when the variable is compared directly, with no intermediate copy and no user-defined Procedure involved.
As a consequence, passing a string variable as an argument into a user-defined Procedure (which involves an implicit copy into the formal parameter) also fails for the same reason as (1)/(2), since the formal parameter never receives the actual string value.

None of these produce a parse-time error; they are only surfaced as evaluation/solve failures (or, in case 1, no failure at all — just a silently wrong numeric value), which makes them easy to miss.

Environment

CoolSolve version: (0.2)
OS / platform: (linux mint)

Minimal reproduction — Case 1: string-to-string assignment silently fails

layout_teste$='staggered'
coisinha$=layout_teste$

Console output:

Starting solve...
Solve started
Parsing...
Block 1/2 solving...
Block 1/2 solved (0 iter)
Block 2/2 solving...
Block 2/2 solved (0 iter)
Solve SUCCESS
Equations: 2, Variables: 2
Blocks: 2, Largest: 1
Total iterations: 0
Time: 0 ms (solve: 0 ms)
Variables solved: 2

Name Units Initial Value
coisinha$ — — 0
layout_teste$ — — 0
layout_teste$ — — 'staggered'
3 of 3 variables

Expected: coisinha$ should resolve to 'staggered' (the value of layout_teste$).

Observed: coisinha$ resolves to 0. The solve reports SUCCESS with no warning or error — the wrong value is produced silently. Also note layout_teste$ itself appears as two separate rows in the variable table (0 and 'staggered'), which may be a related display/internal-representation issue worth investigating alongside this.

Minimal reproduction — Case 2: direct string comparison inside IF() fails

This is the same variable, compared directly against a literal inside IF(), with no copy to another variable and no Procedure involved:
layout_teste$ = 'staggered'

resultado_e = IF(layout_teste$ = 'staggered', 10, 20)

console output:

Starting solve...
Solve started
Parsing...
Block 1/2 solving...
Block 1/2 solved (0 iter)
Block 2/2 solving...
Block 2/2 FAILED (res=0.000000)
Solve FAILED: Block 1 (size 1, vars: resultado_e) failed: EvaluationError - Unknown fluid:
Unknown fluid:
Block 1: EvaluationError (res=0.00e+0) Unknown fluid:
--- Diagnostics (2) ---
[error]: Block 1 (1 vars) failed to converge: EvaluationError (residual=0.000000)
[error]: Block 1 (1 vars) failed to converge: EvaluationError (residual=0.000000)

Name Units Initial Value
layout_teste$ — — 0
layout_teste$ — — 'staggered'
resultado_e — — 1
3 of 3 variables
Expected: resultado_e = 10 (since layout_teste$ = 'staggered' should be true).

Observed: Solve fails with EvaluationError - Unknown fluid:. The error message is misleading — no fluid-property function (e.g. density(), viscosity()) is used anywhere in this script, so "Unknown fluid" appears to be a generic/fallback error message surfaced from an unrelated internal code path when it encounters this string-comparison expression, rather than a message describing the actual problem.

Additional context

We ran into this while building a larger heat-exchanger sizing script that used a string variable (layout$, values 'staggered'/'inline') to select between two correlations inside a Called Procedure, via IF(layout_in$ = 'staggered', formula_a, formula_b). That failed with the same Unknown fluid error on the first Procedure call that used a string parameter (all earlier blocks using only numeric IF() conditions solved without issue). The two isolated cases above narrowed the cause down to string handling itself, independent of Procedures.

Workaround used: we replaced the string variable with a numeric flag (e.g. layout_flag = 1 for staggered / 0 for inline) set directly by the user, and rewrote every comparison as IF(layout_flag > 0, formula_a, formula_b). This works correctly and converges as expected. However, this workaround means string variables and string comparisons are currently unusable in CoolSolve for any purpose beyond perhaps display/logging.

Suggested fix direction

Investigate why EvaluationError is generic and unrelated to the actual failure (misleading "Unknown fluid" message) — a clearer error type/message here would have saved significant debugging time.
Investigate why simple string-to-string variable assignment does not propagate the value (Case 1) — this is especially concerning because it fails silently (Solve SUCCESS) rather than raising an error, which can produce incorrect results without any warning.
Confirm whether string comparison inside IF() is intended to be supported at all; if so, fix it; if not, please update the documentation (docs/language_reference.md) to state this limitation explicitly, since it currently reads as supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions