8000 Pure code can capture a foul function with ~ and have it run · Issue #640 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Pure code can capture a foul function with ~ and have it run #640

Closed

Description

@akoskovacs

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingConfirmed IssueBug is reproduced on the current development versionTypechecker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0