diff --git a/dhall/dhall-lang b/dhall/dhall-lang index deefb8667..8e11efde7 160000 --- a/dhall/dhall-lang +++ b/dhall/dhall-lang @@ -1 +1 @@ -Subproject commit deefb8667871af9ea10b42dbd86a49aa27b6ecff +Subproject commit 8e11efde7c57c36259ebf4c01c50753025c51812 diff --git a/dhall/dhall.cabal b/dhall/dhall.cabal index e18a57a7c..fe7ccf6c4 100644 --- a/dhall/dhall.cabal +++ b/dhall/dhall.cabal @@ -159,6 +159,7 @@ Extra-Source-Files: dhall-lang/Prelude/Natural/toDouble dhall-lang/Prelude/Natural/toInteger dhall-lang/Prelude/Natural/*.dhall + dhall-lang/Prelude/NonEmpty/*.dhall dhall-lang/Prelude/Operator/package.dhall dhall-lang/Prelude/Optional/all dhall-lang/Prelude/Optional/any diff --git a/dhall/src/Dhall/Import.hs b/dhall/src/Dhall/Import.hs index 6fdfe8d4d..0583139ae 100644 --- a/dhall/src/Dhall/Import.hs +++ b/dhall/src/Dhall/Import.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveDataTypeable #-} @@ -7,6 +8,7 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -Wall #-} @@ -167,6 +169,7 @@ import Data.List.NonEmpty (NonEmpty (..)) import Data.Text (Text) import Data.Typeable (Typeable) import Data.Void (Void, absurd) +import Dhall.TypeCheck (TypeError) import Dhall.Syntax ( Chunks (..) @@ -201,6 +204,7 @@ import Lens.Family.State.Strict (zoom) import qualified Codec.CBOR.Write as Write import qualified Codec.Serialise +import qualified Control.Exception as Exception import qualified Control.Monad.State.Strict as State import qualified Control.Monad.Trans.Maybe as Maybe import qualified Data.ByteString @@ -208,6 +212,7 @@ import qualified Data.ByteString.Lazy import qualified Data.CaseInsensitive import qualified Data.Foldable import qualified Data.List.NonEmpty as NonEmpty +import qualified Data.Maybe as Maybe import qualified Data.Text as Text import qualified Data.Text.Encoding import qualified Data.Text.IO @@ -1157,11 +1162,29 @@ loadWith expr₀ = case expr₀ of ImportAlt a b -> loadWith a `catch` handler₀ where - handler₀ (SourcedException (Src begin _ text₀) (MissingImports es₀)) = - loadWith b `catch` handler₁ + is :: forall e . Exception e => SomeException -> Bool + is exception = Maybe.isJust (Exception.fromException @e exception) + + isNotResolutionError exception = + is @(Imported (TypeError Src Void)) exception + || is @(Imported Cycle ) exception + || is @(Imported HashMismatch ) exception + || is @(Imported ParseError ) exception + + handler₀ exception₀@(SourcedException (Src begin _ text₀) (MissingImports es₀)) + | any isNotResolutionError es₀ = + throwM exception₀ + | otherwise = do + loadWith b `catch` handler₁ where - handler₁ (SourcedException (Src _ end text₁) (MissingImports es₁)) = - throwM (SourcedException (Src begin end text₂) (MissingImports (es₀ ++ es₁))) + handler₁ exception₁@(SourcedException (Src _ end text₁) (MissingImports es₁)) + | any isNotResolutionError es₁ = + throwM exception₁ + | otherwise = + -- Fix the source span for the error message to encompass both + -- alternatives, since both are equally to blame for the + -- failure if neither succeeds. + throwM (SourcedException (Src begin end text₂) (MissingImports (es₀ ++ es₁))) where text₂ = text₀ <> " ? " <> text₁ diff --git a/dhall/tests/Dhall/Test/Import.hs b/dhall/tests/Dhall/Test/Import.hs index f7e235b83..97d7c0232 100644 --- a/dhall/tests/Dhall/Test/Import.hs +++ b/dhall/tests/Dhall/Test/Import.hs @@ -156,9 +156,8 @@ failureTest path = do let pathString = Text.unpack path Tasty.HUnit.testCase pathString (do - text <- Text.IO.readFile pathString - - actualExpr <- Core.throws (Parser.exprFromText mempty text) + actualExpr <- do + Core.throws (Parser.exprFromText mempty (Test.Util.toDhallPath path)) succeeded <- Exception.catch @SomeException (do _ <- Test.Util.load actualExpr