You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pure code can capture a foul function with ~ and have it run #640
A pure function can capture a foul function with ~ and hand it to a higher-order function, which then runs it. The checker reports nothing.
Repro
foul shout(s: String) -> String do
IO.printLine(s)
s
end
let quiet(xs: [String]) -> [String] = xs.map(~shout)
main do
IO.printLine("${quiet(["a"])}")
end
Actual: accepted, and the pure quiet prints a as a side effect before the result [a].
Expected: an error at ~shout, as a direct call gives (Cannot call foul function 'shout' from pure context).
Cause
The analyzer's ast::CurryExpr case only walks the capture's arguments and never looks at whether the captured function is foul (src/semantic/analyzer.cxx:721-726). The call cases just above it do check (analyzer.cxx:498-519).
Related to #142, which is the harder version (a foul block that is already a value). This one names the foul function in pure code, so it can be rejected without effect types.
Reproduced on kex 0.4.0-rc.3 (266b7a60) with the type checker on.
Activity