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):
- 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).
- 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
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 likeCannot index into Nothing - Expected List of Unknown but found Nothingand cascadingCannot 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.wflsections that return a query from an action run fine but emit these warnings.Environment
26.7.4, Linux, currentmainReproduction
Databases not required — any value-returning action shows it:
Output (program still runs and prints
1):Root cause
In
src/typechecker/mod.rs,Statement::ActionDefinitionhandling registers the action's symbol type with:An unannotated action is recorded as
Function { ..., return_type: Nothing }, andExpression::ActionCallinference then propagatesNothingas 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):
return/give backstatements (unify multiple returns;Nothingonly when there is no value-returning return statement).Unknowninstead ofNothing, 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
return query/execute ... and parameters [...]fails ("Unexpected token in expression: KeywordParameters") #559 (return query ... and parameters [...]), whose doc example triggers the warning.store <var> as <builtin> of ...inside an included file fails inference ('Could not infer type') — follow-on to #547 #551 and Type checker: more RHS forms fail inference inside included files — index / object-index / comparison /length of(follow-on to #551) #553.