Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user facing unit type #1416

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
### Removed
### Fixed

- Fix a problem where sum types with no parameters were being printed with
either Quint's unit type `()` or Apalache's unit type `"U_OF_UNIT"` (#1416).

### Security

## v0.19.0 -- 2024-03-25
Expand Down
4 changes: 2 additions & 2 deletions quint/src/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export function prettyQuintEx(ex: QuintEx): Doc {

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

return group([label, ...value])
Expand Down
6 changes: 6 additions & 0 deletions quint/src/itf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ export function ofItf(itf: ItfTrace): QuintEx[] {
if (typeof value === 'boolean') {
return { id, kind: 'bool', value }
} else if (typeof value === 'string') {
if (value === 'U_OF_UNIT') {
// Apalache converts empty tuples to its unit value, "U_OF_UNIT".
// We need to convert it back to Quint's unit value, the empty tuple.
return { id, kind: 'app', opcode: 'Tup', args: [] }
}

return { id, kind: 'str', value }
} else if (isBigint(value)) {
// this is the standard way of encoding an integer in ITF.
Expand Down
24 changes: 24 additions & 0 deletions quint/test/itf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,28 @@ describe('toItf', () => {
`round trip conversion of trace failed`
)
})

it('converts unit type from Apalache', () => {
const text = '{ a: () }'

const trace = [buildExpression(text)]
const vars = ['a']
const itfTrace = {
vars: vars,
states: [
{
'#meta': {
index: 0,
},
a: 'U_OF_UNIT',
},
],
}

const roundTripTrace = ofItf(itfTrace)
assert(
zip(roundTripTrace, trace).every(([a, b]) => quintExAreEqual(a, b)),
`round trip conversion of trace failed`
)
})
})
Loading