1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 14:13:27 +03:00

Fix for crash with wildcard used in type definition (#2405)

- Closes #2292.

Holes are now allowed in the type of inductive parameters.
If the type is unsupported, a user error is thrown.
This commit is contained in:
Jan Mas Rovira 2023-10-02 18:58:21 +02:00 committed by GitHub
parent dad3963c00
commit 76b58f090f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 5 deletions

View File

@ -50,6 +50,7 @@ data ScoperError
| ErrIncomparablePrecedences IncomaprablePrecedences
| ErrAliasCycle AliasCycle
| ErrInvalidRangeNumber InvalidRangeNumber
| ErrUnsupported Unsupported
instance ToGenericError ScoperError where
genericError = \case
@ -91,3 +92,4 @@ instance ToGenericError ScoperError where
ErrIncomparablePrecedences e -> genericError e
ErrAliasCycle e -> genericError e
ErrInvalidRangeNumber e -> genericError e
ErrUnsupported e -> genericError e

View File

@ -929,3 +929,21 @@ instance ToGenericError AliasCycle where
where
i :: Interval
i = getLoc _aliasCycleDef
data Unsupported = Unsupported
{ _unsupportedMsg :: Text,
_unsupportedLoc :: Interval
}
deriving stock (Show)
instance ToGenericError Unsupported where
genericError Unsupported {..} = do
return
GenericError
{ _genericErrorLoc = i,
_genericErrorMessage = mkAnsiText _unsupportedMsg,
_genericErrorIntervals = [i]
}
where
i :: Interval
i = _unsupportedLoc

View File

@ -39,9 +39,6 @@ type MCache = Cache Concrete.ModuleIndex Internal.Module
-- | Needed to generate field projections.
type ConstructorInfos = HashMap Internal.ConstructorName ConstructorInfo
unsupported :: Text -> a
unsupported msg = error $ msg <> "Scoped to Internal: not yet supported"
fromConcrete ::
(Members '[Reader EntryPoint, Error JuvixError, Builtins, NameIdGen, Termination] r) =>
Scoper.ScoperResult ->
@ -537,7 +534,14 @@ goInductiveParameters params@InductiveParameters {..} = do
paramType' <- goRhs _inductiveParametersRhs
case paramType' of
Internal.ExpressionUniverse {} -> return ()
_ -> unsupported "only type variables of small types are allowed"
Internal.ExpressionHole {} -> return ()
_ ->
throw $
ErrUnsupported
Unsupported
{ _unsupportedMsg = "only type variables of small types are allowed",
_unsupportedLoc = getLoc params
}
let goInductiveParameter :: S.Symbol -> Internal.InductiveParameter
goInductiveParameter var =

View File

@ -350,5 +350,12 @@ scoperErrorTests =
$(mkRelFile "DanglingDoubleBrace.juvix")
$ \case
ErrDanglingDoubleBrace {} -> Nothing
_ -> wrongError,
NegTest
"Unsupported type"
$(mkRelDir ".")
$(mkRelFile "UnsupportedType.juvix")
$ \case
ErrUnsupported {} -> Nothing
_ -> wrongError
]

View File

@ -292,7 +292,11 @@ tests =
posTest
"Hole as numeric type"
$(mkRelDir "issue2373")
$(mkRelFile "Main.juvix")
$(mkRelFile "Main.juvix"),
posTest
"Hole in type parameter"
$(mkRelDir ".")
$(mkRelFile "HoleTypeParameter.juvix")
]
<> [ compilationTest t | t <- Compilation.tests
]

View File

@ -0,0 +1,5 @@
module UnsupportedType;
type List' (A : Type -> Type) :=
| nil'
| cons' A (List' A);

View File

@ -0,0 +1,5 @@
module HoleTypeParameter;
type List' (A : _) :=
| nil'
| cons' A (List' A);