Skip to content

Commit

Permalink
[ fix ] Add cast from Int to ExitCode to Libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
spcfox committed Dec 3, 2024
1 parent d8d360a commit 49fd711
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Core/Core.idr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Libraries.Text.PrettyPrint.Prettyprinter
import Libraries.Text.PrettyPrint.Prettyprinter.Util
import Libraries.Text.PrettyPrint.Prettyprinter.Doc
import Libraries.Data.Tap
import Libraries.System

import public Data.IORef
import System
Expand Down Expand Up @@ -989,7 +990,7 @@ handleExitCode cmd (ExitFailure status) = throw $ NonZeroExitCode cmd status

export
system : String -> Core ExitCode
system = map cast . coreLift . system
system = map (cast @{ToExitCode}) . coreLift . system

||| Execute a shell command. Throws `NonZeroExitCode` if the command returns
||| non-zero exit code.
Expand All @@ -1000,7 +1001,7 @@ safeSystem cmd = system cmd >>= handleExitCode cmd
namespace Escaped
export
system : List String -> Core ExitCode
system = map cast . coreLift . system
system = map (cast @{ToExitCode}) . coreLift . system

export
safeSystem : List String -> Core ()
Expand Down
11 changes: 11 additions & 0 deletions src/Libraries/System.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Libraries.System

import System

-- TODO: Remove this, once `Cast` from `base` is available to the compiler

export
[ToExitCode] Cast Int ExitCode where
cast code with (code == 0) proof prf
_ | True = ExitSuccess
_ | False = ExitFailure code @{rewrite prf in Oh}

0 comments on commit 49fd711

Please sign in to comment.