Skip to content

bug: dead code in flattenParams() overwrites result before using it (intent/parser.go) #66

@jpleva91

Description

@jpleva91

Bug: Dead Code in flattenParams

File: internal/intent/parser.go ~line 351

Description

In the flattenParams function, for float64 values that are whole numbers, the code computes a value via a complex strings.TrimRight/strings.Replace chain and assigns it to result[k] — then immediately overwrites it with fmt.Sprintf("%g", val) on the very next line. The first assignment is dead code and never used.

Reproduction

case float64:
    if val == float64(int(val)) {
        result[k] = strings.TrimRight(strings.TrimRight(   // ← DEAD: immediately overwritten
            strings.Replace(
                strings.Replace(
                    fmt.Sprintf("%f", val), ".", "", 1),
                "0", "", -1),
            "0"), "")
        // Simpler: just use Sprintf
        result[k] = fmt.Sprintf("%g", val)               // ← actual assignment
    }

Fix

Remove the dead first assignment. Both integer and non-integer float64 values should use the same fmt.Sprintf("%g", val) path:

case float64:
    result[k] = fmt.Sprintf("%g", val)

Impact

  • Dead code clutters the function and confuses future readers (the comment says "Simpler: just use Sprintf" but leaves the original around)
  • No behavioral impact at runtime since the second assignment wins

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium prioritybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions