Skip to content

Commit 40d0d39

Browse files
authored
dhall-toml: Fix loading of relative paths (#2607)
Fixes #2606
1 parent f4412a0 commit 40d0d39

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

dhall-toml/dhall-toml.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Library
3636
Build-Depends:
3737
base >= 4.12 && < 5 ,
3838
dhall >= 1.39.0 && < 1.43 ,
39+
filepath < 1.6 ,
3940
tomland >= 1.3.2.0 && < 1.4 ,
4041
text >= 0.11.1.0 && < 2.2 ,
4142
containers >= 0.5.9 && < 0.8 ,

dhall-toml/src/Dhall/Toml/Utils.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ module Dhall.Toml.Utils
1010

1111
import Data.Text (Text)
1212
import Data.Void (Void)
13+
import Dhall.Import (SemanticCacheMode(..))
1314
import Dhall.Parser (Src)
1415

1516
import qualified Data.Text.IO as Text.IO
1617
import qualified Dhall.Core as Core
1718
import qualified Dhall.Import
1819
import qualified Dhall.Parser
1920
import qualified Dhall.TypeCheck
21+
import qualified System.FilePath as FilePath
2022

2123
-- | Read the file fileName and return the normalized Dhall AST
2224
fileToDhall :: String -> IO (Core.Expr Src Void)
@@ -35,9 +37,15 @@ inputToDhall = do
3537
-- by the parser for generating error messages.
3638
textToDhall :: String -> Text -> IO (Core.Expr Src Void)
3739
textToDhall fileName text = do
38-
parsedExpression <-
40+
parsedExpression <- do
3941
Core.throws (Dhall.Parser.exprFromText fileName text)
40-
resolvedExpression <- Dhall.Import.load parsedExpression
42+
43+
let directory = FilePath.takeDirectory fileName
44+
45+
resolvedExpression <- do
46+
Dhall.Import.loadRelativeTo directory UseSemanticCache parsedExpression
47+
4148
_ <- Core.throws (Dhall.TypeCheck.typeOf resolvedExpression)
49+
4250
return resolvedExpression
4351

0 commit comments

Comments
 (0)