Skip to content

Commit

Permalink
Negative tests for --new-typechecker (#2532)
Browse files Browse the repository at this point in the history
Adds all existing negative tests for the new typechecker.
- Depends on #2524
  • Loading branch information
janmasrovira authored Nov 28, 2023
1 parent d6c1a74 commit ca7d0fa
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 60 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 Expand Up @@ -955,7 +955,7 @@ viewInductiveApp ty = do
case r of
Just h' -> viewInductiveApp h'
Nothing -> return (Left h)
_ -> throw (ErrImpracticalPatternMatching (ImpracticalPatternMatching ty))
_ -> throw (ErrInvalidPatternMatching (InvalidPatternMatching ty))
where
viewTypeApp :: Expression -> (Expression, [Expression])
viewTypeApp tyapp = case tyapp of
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 Expand Up @@ -1369,7 +1369,7 @@ viewInductiveApp ty = do
case r of
Just h' -> viewInductiveApp h'
Nothing -> return (Left h)
_ -> throw (ErrImpracticalPatternMatching (ImpracticalPatternMatching ty))
_ -> throw (ErrInvalidPatternMatching (InvalidPatternMatching ty))
where
viewTypeApp :: Expression -> (Expression, [Expression])
viewTypeApp tyapp = case tyapp of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.ArityChecking.E
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Error.Pretty
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Error.Types
import Juvix.Prelude
import Prelude (show)

data TypeCheckerError
= ErrWrongConstructorType WrongConstructorType
| ErrWrongReturnType WrongReturnType
| ErrArity ArityCheckerError
| ErrWrongType WrongType
| ErrUnsolvedMeta UnsolvedMeta
| ErrExpectedFunctionType ExpectedFunctionType
| ErrTooManyArgumentsIndType WrongNumberArgumentsIndType
| ErrTooFewArgumentsIndType WrongNumberArgumentsIndType
| ErrImpracticalPatternMatching ImpracticalPatternMatching
| ErrInvalidPatternMatching InvalidPatternMatching
| ErrNoPositivity NoPositivity
| ErrUnsupportedTypeFunction UnsupportedTypeFunction
| ErrInvalidInstanceType InvalidInstanceType
Expand All @@ -42,13 +42,12 @@ 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
ErrTooManyArgumentsIndType e -> genericError e
ErrTooFewArgumentsIndType e -> genericError e
ErrImpracticalPatternMatching e -> genericError e
ErrInvalidPatternMatching e -> genericError e
ErrNoPositivity e -> genericError e
ErrUnsupportedTypeFunction e -> genericError e
ErrInvalidInstanceType 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"
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ instance ToGenericError WrongNumberArgumentsIndType where
)
<+> "given"

newtype ImpracticalPatternMatching = ImpracticalPatternMatching
newtype InvalidPatternMatching = InvalidPatternMatching
{ _impracticalPatternMatchingType :: Expression
}

makeLenses ''ImpracticalPatternMatching
makeLenses ''InvalidPatternMatching

instance ToGenericError ImpracticalPatternMatching where
instance ToGenericError InvalidPatternMatching where
genericError e = ask >>= generr
where
generr opts =
Expand Down
2 changes: 1 addition & 1 deletion test/Arity/Negative.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Arity.Negative (allTests) where
module Arity.Negative where

import Base
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.ArityChecking.Error
Expand Down
3 changes: 2 additions & 1 deletion test/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module Typecheck (allTests) where

import Base
import Typecheck.Negative qualified as N
import Typecheck.NegativeNew qualified as NewNeg
import Typecheck.Positive qualified as P
import Typecheck.PositiveNew qualified as New

allTests :: TestTree
allTests = testGroup "Type checker tests" [New.allTests, P.allTests, N.allTests]
allTests = testGroup "Type checker tests" [New.allTests, P.allTests, N.allTests, NewNeg.allTests]
Loading

0 comments on commit ca7d0fa

Please sign in to comment.