Skip to content

Commit

Permalink
fix negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Nov 28, 2023
1 parent 361503b commit f391467
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ matchIsImplicit expected actual =
unless
(expected == actual ^. patternArgIsImplicit)
( throw
( ErrArity
( ErrArityCheckerError
( ErrWrongPatternIsImplicit
WrongPatternIsImplicit
{ _wrongPatternIsImplicitExpected = expected,
Expand Down Expand Up @@ -629,7 +629,7 @@ checkPattern = go
return app {_constrAppType = Just appTy, _constrAppParameters = pis}
appErr :: ConstructorApp -> Int -> TypeCheckerError
appErr app expected =
ErrArity
ErrArityCheckerError
( ErrWrongConstructorAppLength
( WrongConstructorAppLength
{ _wrongConstructorAppLength = app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ matchIsImplicit expected actual =
unless
(expected == actual ^. patternArgIsImplicit)
. throw
. ErrArity
. ErrArityCheckerError
$ ErrWrongPatternIsImplicit
WrongPatternIsImplicit
{ _wrongPatternIsImplicitExpected = expected,
Expand Down Expand Up @@ -745,7 +745,7 @@ checkPattern = go

appErr :: ConstructorApp -> Int -> TypeCheckerError
appErr app expected =
ErrArity
ErrArityCheckerError
( ErrWrongConstructorAppLength
( WrongConstructorAppLength
{ _wrongConstructorAppLength = app,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Er
)
where

import Prelude (show)
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.ArityChecking.Error
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Error.Pretty
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Error.Types
Expand All @@ -14,7 +15,6 @@ import Juvix.Prelude
data TypeCheckerError
= ErrWrongConstructorType WrongConstructorType
| ErrWrongReturnType WrongReturnType
| ErrArity ArityCheckerError
| ErrWrongType WrongType
| ErrUnsolvedMeta UnsolvedMeta
| ErrExpectedFunctionType ExpectedFunctionType
Expand Down Expand Up @@ -42,7 +42,6 @@ instance ToGenericError TypeCheckerError where
genericError = \case
ErrWrongConstructorType e -> genericError e
ErrWrongReturnType e -> genericError e
ErrArity e -> genericError e
ErrWrongType e -> genericError e
ErrUnsolvedMeta e -> genericError e
ErrExpectedFunctionType e -> genericError e
Expand All @@ -64,3 +63,29 @@ instance ToGenericError TypeCheckerError where
ErrTraitNotTerminating e -> genericError e
ErrArityCheckerError e -> genericError e
ErrDefaultArgLoop e -> genericError e

instance Show TypeCheckerError where
show = \case
ErrWrongConstructorType {} -> "ErrWrongConstructorType"
ErrWrongReturnType {} -> "ErrWrongReturnType"
ErrWrongType {} -> "ErrWrongType"
ErrUnsolvedMeta {} -> "ErrUnsolvedMeta"
ErrExpectedFunctionType {} -> "ErrExpectedFunctionType"
ErrTooManyArgumentsIndType {} -> "ErrTooManyArgumentsIndType"
ErrTooFewArgumentsIndType {} -> "ErrTooFewArgumentsIndType"
ErrInvalidPatternMatching {} -> "ErrInvalidPatternMatching"
ErrNoPositivity {} -> "ErrNoPositivity"
ErrUnsupportedTypeFunction {} -> "ErrUnsupportedTypeFunction"
ErrInvalidInstanceType {} -> "ErrInvalidInstanceType"
ErrInvalidCoercionType {} -> "ErrInvalidCoercionType"
ErrWrongCoercionArgument {} -> "ErrWrongCoercionArgument"
ErrCoercionCycles {} -> "ErrCoercionCycles"
ErrTargetNotATrait {} -> "ErrTargetNotATrait"
ErrNotATrait {} -> "ErrNotATrait"
ErrNoInstance {} -> "ErrNoInstance"
ErrAmbiguousInstances {} -> "ErrAmbiguousInstances"
ErrSubsumedInstance {} -> "ErrSubsumedInstance"
ErrExplicitInstanceArgument {} -> "ErrExplicitInstanceArgument"
ErrTraitNotTerminating {} -> "ErrTraitNotTerminating"
ErrArityCheckerError {} -> "ErrArityCheckerError"
ErrDefaultArgLoop {} -> "ErrDefaultArgLoop"
4 changes: 2 additions & 2 deletions test/Typecheck/Negative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ tests =
$(mkRelDir "issue1337")
$(mkRelFile "Braces.juvix")
$ \case
ErrArity (ErrWrongPatternIsImplicit {}) -> Nothing
ErrArityCheckerError (ErrWrongPatternIsImplicit {}) -> Nothing
_ -> wrongError,
negTest
"Unexpected double braces in pattern"
$(mkRelDir "issue1337")
$(mkRelFile "DoubleBraces.juvix")
$ \case
ErrArity (ErrWrongPatternIsImplicit {}) -> Nothing
ErrArityCheckerError (ErrWrongPatternIsImplicit {}) -> Nothing
_ -> wrongError,
negTest
"Wrong return type name for a constructor of a simple data type"
Expand Down
4 changes: 2 additions & 2 deletions test/Typecheck/NegativeNew.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ testDescr Old.NegTest {..} =
_testRoot = tRoot,
_testAssertion = Single $ do
entryPoint <- set entryPointNewTypeCheckingAlgorithm True <$> defaultEntryPointIO' LockModeExclusive tRoot file'
result <- runIOEither' LockModeExclusive entryPoint upToInternalTyped
result <- runIOEither' LockModeExclusive entryPoint upToCore
case mapLeft fromJuvixError result of
Left (Just tyError) -> whenJust (_checkErr tyError) assertFailure
Left Nothing -> assertFailure "An error ocurred but it was not in the type checker."
Expand Down Expand Up @@ -70,7 +70,7 @@ negArityTest _name rdir rfile ariErr =
{ _file = _dir <//> rfile,
_checkErr = \case
ErrArityCheckerError e -> ariErr e
_ -> wrongError,
e -> error (show e),
_name,
_dir
}
Expand Down

0 comments on commit f391467

Please sign in to comment.