From ae24c18714e8ced7d5b4a7a618f4d32fd7ab8fad Mon Sep 17 00:00:00 2001 From: Gabriella Gonzalez Date: Tue, 1 Oct 2024 17:37:17 +0200 Subject: [PATCH] `dhall-toml`: Fix loading of relative paths Fixes https://github.com/dhall-lang/dhall-haskell/issues/2606 --- dhall-toml/dhall-toml.cabal | 1 + dhall-toml/src/Dhall/Toml/Utils.hs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dhall-toml/dhall-toml.cabal b/dhall-toml/dhall-toml.cabal index 9cda76193..c15c48aa1 100644 --- a/dhall-toml/dhall-toml.cabal +++ b/dhall-toml/dhall-toml.cabal @@ -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 , diff --git a/dhall-toml/src/Dhall/Toml/Utils.hs b/dhall-toml/src/Dhall/Toml/Utils.hs index 4fd5b3e75..39c6d5f04 100644 --- a/dhall-toml/src/Dhall/Toml/Utils.hs +++ b/dhall-toml/src/Dhall/Toml/Utils.hs @@ -10,6 +10,7 @@ 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 @@ -17,6 +18,7 @@ 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) @@ -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