Skip to content

Commit

Permalink
Only use literal type hint if inferred type is Nat
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Apr 12, 2023
1 parent d9b1c2b commit fa6db95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,14 @@ inferExpression' hint e = case e of
where
typedLitInteger :: Integer -> Sem r TypedExpression
typedLitInteger v = do
ty <- case hint of
Nothing -> inferLitTypeFromValue
Just ExpressionHole {} -> inferLitTypeFromValue
Just exp -> return exp
inferredTy <- inferLitTypeFromValue
natTy <- getNatTy
let ty = case hint of
Nothing -> inferredTy
Just ExpressionHole {} -> inferredTy
Just hintTy -> if
| inferredTy == natTy -> hintTy
| otherwise -> inferredTy
lit' <- WithLoc i <$> valueFromType ty
return
TypedExpression
Expand Down
9 changes: 8 additions & 1 deletion test/Typecheck/Negative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ tests =
$(mkRelFile "SelfApplication.juvix")
$ \case
ErrUnsolvedMeta {} -> Nothing
_ -> wrongError
_ -> wrongError,
NegTest
"Negative integer literal cannot be used as a Nat"
$(mkRelDir "Internal")
$(mkRelFile "LiteralInteger.juvix")
$ \case
ErrWrongType {} -> Nothing
_ -> wrongError
]

negPositivityTests :: [NegTest]
Expand Down
6 changes: 6 additions & 0 deletions tests/negative/Internal/LiteralInteger.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module LiteralInteger;

open import Stdlib.Prelude;

h : Nat;
h := div 1 -2;

0 comments on commit fa6db95

Please sign in to comment.