Skip to content

Commit d2c2dea

Browse files
author
Shon Feder
authored
Merge pull request #1371 from informalsystems/1177/via-param-annotations
Constrain operator parameters by their type annotations
2 parents 5d28bbe + 88e7bbe commit d2c2dea

18 files changed

+1428
-1164
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
### Deprecated
4040
### Removed
4141
### Fixed
42+
43+
- Fixed type checker to account for type constraints on annotated operator
44+
parameters when checking operator bodies (#1177).
45+
4246
### Security
4347

4448
## v0.18.1 -- 2024-01-16

quint/src/generated/Quint.g4

+28-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ documentedDeclaration : DOCCOMMENT* declaration;
2525
// a module declaration
2626
declaration : 'const' qualId ':' type # const
2727
| 'var' qualId ':' type # var
28-
| 'assume' identOrHole '=' expr # assume
28+
| 'assume' (assumeName=identOrHole) '=' expr # assume
2929
| instanceMod # instance
3030
| operDef # oper
3131
| typeDef # typeDefs
@@ -39,17 +39,28 @@ declaration : 'const' qualId ':' type # const
3939
;
4040

4141
// An operator definition.
42-
// We embed two kinds of parameters right in this rule.
43-
// Otherwise, the parser would start recognizing parameters everywhere.
44-
operDef : qualifier normalCallName
45-
( /* ML-like parameter lists */
46-
'(' (parameter (',' parameter)*)? ')' (':' type)?
47-
| ':' type
48-
/* C-like parameter lists */
49-
| '(' (parameter ':' type (',' parameter ':' type)*) ')' ':' type
50-
)?
51-
('=' expr)? ';'?
52-
;
42+
operDef
43+
: qualifier normalCallName
44+
// Fully-annotated parameter list with at least one parameter
45+
'(' (annotOperParam+=annotatedParameter (',' annotOperParam+=annotatedParameter)*) ')'
46+
// Mandatory annotation for return type
47+
':' type
48+
// We support header declaration with no implementation for documentation genaration
49+
('=' expr)?
50+
// Optionally terminated with a semicolon
51+
';'?
52+
# annotatedOperDef
53+
| qualifier normalCallName // TODO: Remove as per https://github.com/informalsystems/quint/issues/923
54+
// Unannotated parameter list
55+
('(' (operParam+=parameter (',' operParam+=parameter)*)? ')')?
56+
// Optional type annotation using the deprecated format
57+
(':' annotatedRetType=type)?
58+
// We support header declaration with no implementation for documentation genaration
59+
('=' expr)?
60+
// Optionally terminated with a semicolon
61+
';'?
62+
# deprecatedOperDef
63+
;
5364

5465
typeDef
5566
: 'type' qualId # typeAbstractDef
@@ -205,10 +216,12 @@ lambdaUnsugared : parameter '=>' expr
205216
lambdaTupleSugar : '(' '(' parameter (',' parameter)+ ')' ')' '=>' expr;
206217

207218
// an identifier or a hole '_'
208-
identOrHole : '_' | qualId
209-
;
219+
identOrHole : '_' | qualId;
210220

211-
parameter: identOrHole;
221+
// TODO: Combine these into a single rule that support optionally annotated parameters
222+
// Requires https://github.com/informalsystems/quint/issues/923
223+
parameter: paramName=identOrHole;
224+
annotatedParameter: paramName=identOrHole ':' type;
212225

213226
// an identifier or a star '*'
214227
identOrStar : '*' | qualId

quint/src/generated/Quint.interp

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quint/src/generated/QuintListener.ts

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)