Skip to content

Commit

Permalink
dhall-toml: Fix loading of relative paths
Browse files Browse the repository at this point in the history
Fixes #2606
  • Loading branch information
Gabriella439 committed Oct 1, 2024
1 parent f4412a0 commit ae24c18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions dhall-toml/dhall-toml.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Library
Build-Depends:
base >= 4.12 && < 5 ,
dhall >= 1.39.0 && < 1.43 ,
filepath < 1.6 ,
tomland >= 1.3.2.0 && < 1.4 ,
text >= 0.11.1.0 && < 2.2 ,
containers >= 0.5.9 && < 0.8 ,
Expand Down
12 changes: 10 additions & 2 deletions dhall-toml/src/Dhall/Toml/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ module Dhall.Toml.Utils

import Data.Text (Text)
import Data.Void (Void)
import Dhall.Import (SemanticCacheMode(..))
import Dhall.Parser (Src)

import qualified Data.Text.IO as Text.IO
import qualified Dhall.Core as Core
import qualified Dhall.Import
import qualified Dhall.Parser
import qualified Dhall.TypeCheck
import qualified System.FilePath as FilePath

-- | Read the file fileName and return the normalized Dhall AST
fileToDhall :: String -> IO (Core.Expr Src Void)
Expand All @@ -35,9 +37,15 @@ inputToDhall = do
-- by the parser for generating error messages.
textToDhall :: String -> Text -> IO (Core.Expr Src Void)
textToDhall fileName text = do
parsedExpression <-
parsedExpression <- do
Core.throws (Dhall.Parser.exprFromText fileName text)
resolvedExpression <- Dhall.Import.load parsedExpression

let directory = FilePath.takeDirectory fileName

resolvedExpression <- do
Dhall.Import.loadRelativeTo directory UseSemanticCache parsedExpression

_ <- Core.throws (Dhall.TypeCheck.typeOf resolvedExpression)

return resolvedExpression

0 comments on commit ae24c18

Please sign in to comment.