Skip to content

Commit 1680708

Browse files
authored
Merge pull request #1416 from informalsystems/gabriela/fix-user-facing-unit-type
Fix user facing unit type
2 parents 5e29acc + 7cc7e17 commit 1680708

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Deprecated
1313
### Removed
1414
### Fixed
15+
16+
- Fix a problem where sum types with no parameters were being printed with
17+
either Quint's unit type `()` or Apalache's unit type `"U_OF_UNIT"` (#1416).
18+
1519
### Security
1620

1721
## v0.19.0 -- 2024-03-25

quint/src/graphics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ export function prettyQuintEx(ex: QuintEx): Doc {
108108

109109
const valueExpr = ex.args[1]
110110
const value =
111-
valueExpr.kind === 'app' && valueExpr.opcode === 'Rec' && valueExpr.args.length === 0
112-
? [] // A payload with the empty record is shown as a bare label
111+
valueExpr.kind === 'app' && valueExpr.opcode === 'Tup' && valueExpr.args.length === 0
112+
? [] // A payload with the empty tuple is shown as a bare label
113113
: [text('('), prettyQuintEx(valueExpr), text(')')]
114114

115115
return group([label, ...value])

quint/src/itf.ts

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ export function ofItf(itf: ItfTrace): QuintEx[] {
189189
if (typeof value === 'boolean') {
190190
return { id, kind: 'bool', value }
191191
} else if (typeof value === 'string') {
192+
if (value === 'U_OF_UNIT') {
193+
// Apalache converts empty tuples to its unit value, "U_OF_UNIT".
194+
// We need to convert it back to Quint's unit value, the empty tuple.
195+
return { id, kind: 'app', opcode: 'Tup', args: [] }
196+
}
197+
192198
return { id, kind: 'str', value }
193199
} else if (isBigint(value)) {
194200
// this is the standard way of encoding an integer in ITF.

quint/test/itf.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,28 @@ describe('toItf', () => {
8888
`round trip conversion of trace failed`
8989
)
9090
})
91+
92+
it('converts unit type from Apalache', () => {
93+
const text = '{ a: () }'
94+
95+
const trace = [buildExpression(text)]
96+
const vars = ['a']
97+
const itfTrace = {
98+
vars: vars,
99+
states: [
100+
{
101+
'#meta': {
102+
index: 0,
103+
},
104+
a: 'U_OF_UNIT',
105+
},
106+
],
107+
}
108+
109+
const roundTripTrace = ofItf(itfTrace)
110+
assert(
111+
zip(roundTripTrace, trace).every(([a, b]) => quintExAreEqual(a, b)),
112+
`round trip conversion of trace failed`
113+
)
114+
})
91115
})

0 commit comments

Comments
 (0)