File tree Expand file tree Collapse file tree 5 files changed +57
-2
lines changed Expand file tree Collapse file tree 5 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
### Added
11
11
### Changed
12
+
13
+ - ` quint run ` produces a friendlier message when it meets a ` const ` (#1050 )
14
+
12
15
### Deprecated
13
16
### Removed
14
17
Original file line number Diff line number Diff line change @@ -801,9 +801,43 @@ exit $exit_code
801
801
```
802
802
803
803
_1040compileError
804
+ HOME/_1040compileError.qnt:2:3 - error: QNT500: Uninitialized const n. Use: import <moduleName>(n=<value>).*
805
+ 2: const n: int
806
+ ^^^^^^^^^^^^
807
+
804
808
HOME/_1040compileError.qnt:5:12 - error: Name n not found
805
809
5: assert(n > 0)
806
810
^
807
811
808
812
error: Tests failed
809
813
```
814
+
815
+ ### Fail on run with uninitialized constants
816
+
817
+ <!-- !test in run uninitialized -->
818
+ ```
819
+ output=$(quint run testFixture/_1041compileConst.qnt 2>&1)
820
+ exit_code=$?
821
+ echo "$output" | sed -e 's/([0-9]*ms)/(duration)/g' \
822
+ -e 's#^.*_1041compileConst.qnt# HOME/_1041compileConst.qnt#g'
823
+ exit $exit_code
824
+ ```
825
+
826
+ <!-- !test exit 1 -->
827
+ <!-- !test out run uninitialized -->
828
+ ```
829
+ An example execution:
830
+
831
+ [failure] Found an issue (duration).
832
+ Use --seed=0x0 to reproduce.
833
+ Use --verbosity=3 to show executions.
834
+ <module_input>:2:3 - error: QNT500: Uninitialized const N. Use: import <moduleName>(N=<value>).*
835
+ 2: const N: int
836
+ ^^^^^^^^^^^^
837
+
838
+ <module_input>:5:24 - error: Name N not found
839
+ 5: action init = { x' = N }
840
+ ^
841
+
842
+ error: Runtime error
843
+ ```
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ export type ErrorCode =
43
43
| 'QNT006'
44
44
/* QNT007: Type names must start with an uppercase letter */
45
45
| 'QNT007'
46
+ /* QNT099: Found cyclic definitions */
47
+ | 'QNT099'
46
48
/* QNT101: Conflicting definitions for '<name>' */
47
49
| 'QNT101'
48
50
/* QNT102: Module with name '<name>' was already defined */
@@ -61,8 +63,8 @@ export type ErrorCode =
61
63
| 'QNT406'
62
64
/* QNT407: Cannot import self */
63
65
| 'QNT407'
64
- /* QNT099: Found cyclic definitions */
65
- | 'QNT099 '
66
+ /* QNT500: Unitialized constant */
67
+ | 'QNT500 '
66
68
67
69
/* Additional data for a Quint error */
68
70
export interface QuintErrorData {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import { ExecutionListener } from '../trace'
33
33
import * as ir from '../../quintIr'
34
34
35
35
import { RuntimeValue , rv } from './runtimeValue'
36
+ import { ErrorCode } from '../../quintError'
36
37
37
38
import { lastTraceName } from '../compile'
38
39
@@ -323,6 +324,13 @@ export class CompilerVisitor implements IRVisitor {
323
324
}
324
325
}
325
326
327
+ exitConst ( cdef : ir . QuintConst ) {
328
+ // all constants should be instantiated before running the simulator
329
+ const code : ErrorCode = 'QNT500'
330
+ const msg = `${ code } : Uninitialized const ${ cdef . name } . Use: import <moduleName>(${ cdef . name } =<value>).*`
331
+ this . errorTracker . addCompileError ( cdef . id , msg )
332
+ }
333
+
326
334
exitVar ( vardef : ir . QuintVar ) {
327
335
const varName = vardef . name
328
336
// simply introduce two registers:
Original file line number Diff line number Diff line change
1
+ module _1041compileConst {
2
+ const N: int
3
+ var x: int
4
+
5
+ action init = { x' = N }
6
+
7
+ action step = { x' = x - 1 }
8
+ }
You can’t perform that action at this time.
0 commit comments