Skip to content

Typechecker: unannotated action return types default to Nothing, causing false "Cannot index into Nothing" warnings #560

Description

@logbie

Summary

Calling a user-defined action that has no explicit return type annotation types the call result as Nothing, even when the action clearly returns a value. Any use of that result — indexing, member access, further inference — then produces false typechecker warnings like Cannot index into Nothing - Expected List of Unknown but found Nothing and cascading Cannot determine type of variable '...'. The program runs correctly; only the static diagnostics are wrong.

Noticed while fixing #559: the fix's doc example and TestPrograms/database_sqlite_test.wfl sections that return a query from an action run fine but emit these warnings.

Environment

  • WFL 26.7.4, Linux, current main

Reproduction

Databases not required — any value-returning action shows it:

define action called get_list:
    return [1 and 2]
end action

store xs as call get_list
store x0 as xs[0]
display x0

Output (program still runs and prints 1):

Type checking warnings:
error[ERROR]: Cannot index into Nothing - Expected List of Unknown but found Nothing
  ┌─ rettype.wfl:5:15
  │
5 │ store x0 as xs[0]
  │               ^ Type error occurred here

error[ERROR]: Cannot determine type of variable 'x0'
  ┌─ rettype.wfl:6:9
  │
6 │ display x0
  │         ^ Type error occurred here

Root cause

In src/typechecker/mod.rs, Statement::ActionDefinition handling registers the action's symbol type with:

let return_type_value = return_type.as_ref().cloned().unwrap_or(Type::Nothing);

An unannotated action is recorded as Function { ..., return_type: Nothing }, and Expression::ActionCall inference then propagates Nothing as the call result type. Since WFL actions are commonly written without return type annotations, effectively every value-returning action call is mistyped.

Expected

One of (in order of preference):

  1. Infer the return type from the action body's return/give back statements (unify multiple returns; Nothing only when there is no value-returning return statement).
  2. At minimum, default the unannotated return type to Unknown instead of Nothing, so downstream inference degrades gracefully rather than producing false errors.

Impact

Cosmetic but noisy: false-positive ERROR-level warnings on the very common "small helper action returns a value" pattern, which can drown out real diagnostics and erode trust in the typechecker. Execution is unaffected.

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