Merge pull request #1695 from GaloisInc/issue1593-issue1693

Abort early after type-checking malformed constraint guards
This commit is contained in:
Ryan Scott 2024-07-03 12:41:23 -04:00 committed by GitHub
commit 97e972b025
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 41 additions and 2 deletions

View File

@ -10,6 +10,10 @@
* Fix #1685, which caused Cryptol to panic when given a local definition without
a type signature that uses numeric constraint guards.
* Fix #1593 and #1693, two related bugs that would cause Cryptol to panic when
checking ill-typed constraint guards for exhaustivity.
# 3.1.0 -- 2024-02-05
## Language changes

View File

@ -1234,6 +1234,11 @@ checkSigB b (Forall as asmps0 t0, validSchema) =
asmps1 <- applySubstPreds asmps0
t1 <- applySubst t0
cases1 <- mapM (checkPropGuardCase asmps1) cases0
-- If we recorded any errors when type-checking the constraint guards,
-- then abort early. We don't want to check exhaustivity if there are
-- malformed constraints, as these can cause panics elsewhere during
-- exhaustivity checking (see the `issue{1593,1693}` test cases).
abortIfErrors
exh <- checkExhaustive (P.bName b) as asmps1 (map fst cases1)
unless exh $
@ -1434,7 +1439,7 @@ checkPropGuardCase asmps (P.PropGuardCase guards e0) =
getT ti =
case ti of
P.PosInst t -> t
P.NamedInst {} -> bad "Unexpeceted NamedInst"
P.NamedInst {} -> bad "Unexpected NamedInst"
bad msg = panic "checkPropGuardCase" [msg]

View File

@ -965,7 +965,7 @@ pNegNumeric prop =
where
bad = panic "pNegNumeric"
[ "Unexpeceted numeric constraint:"
[ "Unexpected numeric constraint:"
, pretty prop
]

View File

@ -0,0 +1,5 @@
f : {n, a} [n]a -> [8]
f x
| n == 1 => 0
| n != 1 => 1
| Eq a => 2 // Malformed

View File

@ -0,0 +1 @@
:load issue1593.cry

View File

@ -0,0 +1,7 @@
Loading module Cryptol
Loading module Cryptol
Loading module Main
[error] at issue1593.cry:5:5--5:9:
`Eq` may not be used in a constraint guard.
Constraint guards support only numeric comparisons and `fin`.

View File

@ -0,0 +1,4 @@
f : {n} [n] -> [n+1]
f x
| (fin n) => x # [False]
| (inf n) => x

View File

@ -0,0 +1 @@
:load issue1693.cry

View File

@ -0,0 +1,12 @@
Loading module Cryptol
Loading module Cryptol
Loading module Main
[error] at issue1693.cry:1:5--1:21:
Incorrect type form.
Expected: a constraint
Inferred: a numeric type
[error] at issue1693.cry:4:5--4:12:
Incorrect type form.
Expected: a constraint
Inferred: a numeric type