Skip to content

Typechecker: Any/Unknown values from list indexing and untyped parameters rejected by strict ERROR rules (false positives) #567

Description

@logbie

Summary

Values whose static type is Any (list-index results) or Unknown (untyped action parameters) are rejected by several ERROR-level typechecker rules instead of degrading gracefully. The program runs correctly in every case; only the static diagnostics are wrong.

This is the sibling of #560: that issue covers action-call results being mistyped as Nothing; this one covers Any/Unknown values flowing into operator/statement checks. Together they account for all the false warnings emitted by the rewritten Tools/rust_loc_counter.wfl (a warning-per-shape inventory is at the bottom).

Environment

  • WFL 26.7.6, Linux, release build, current main

Reproduction 1 — list index result (Any) rejected by add ... to

store rows as [[10 and 20]]
store total as 0
for each r in rows:
    store t as r[1]
    add t to total
end for
display total

Output (program still runs and prints 20):

Type checking warnings:
error[ERROR]: Cannot add non-numeric value to number - Expected Number but found Any
  ┌─ repro_any.wfl:5:5
  │
5 │     add t to total
  │     ^ Type error occurred here

The same Any-from-indexing value also trips the subtraction rule (Cannot perform Minus operation on Number and Any) when used as n minus t.

Reproduction 2 — untyped parameter (Unknown) rejected by split ... by

define action called split_words with p:
    store parts as split p by " "
    return parts
end action

store ws as call split_words with "a b"
display "done"

Output (runs fine, prints done):

Type checking warnings:
error[ERROR]: Expected Text for string splitting, got Unknown - Expected Text but found Unknown
  ┌─ repro_unknown.wfl:2:20
  │
2 │     store parts as split p by " "
  │                    ^ Type error occurred here

Note the inconsistency: arithmetic on the same kind of Unknown parameter (length of p then n minus 1) produces no warning, so some rules already treat Unknown as compatible while others reject it.

Expected

Gradual-typing semantics: Any and Unknown should be accepted by these checks (they represent "statically unknown", not "known to be wrong"). Warnings at ERROR level should be reserved for types that are provably incompatible. Concretely:

  • add X to <number> / binary arithmetic: accept Any/Unknown operands
  • split X by Y: accept Any/Unknown for the text operand
  • indexing an Unknown/Any parameter should not cascade into Could not infer type for variable '...' for every downstream variable

Impact

Cosmetic but very noisy: a ~450-line script that leans on untyped action parameters and list rows (e.g. Tools/rust_loc_counter.wfl) emits ~26 ERROR-level warnings on a fully correct program. That drowns out real diagnostics and erodes trust in the typechecker.

Warning inventory from one run of wfl Tools/rust_loc_counter.wfl (all false positives; the tool's output is verified byte-identical to its Python reference):

 8x  Cannot add non-numeric value to number - Expected Number but found Any
 4x  Cannot index into Nothing - Expected List of Unknown but found Nothing   (covered by #560)
 2x  Expected Text for string splitting, got Unknown
 1x  Cannot perform Minus operation on Number and Any
 1x  File content must be a text string - Expected Text but found Nothing     (covered by #560)
 1x  Collection in for-each loop must be a list or map - found Nothing        (covered by #560)
11x  Could not infer type for variable '...' (cascades from indexing an untyped parameter)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions