diff --git a/quint/src/IRprinting.ts b/quint/src/IRprinting.ts index d73379dbb..d63d6e6a0 100644 --- a/quint/src/IRprinting.ts +++ b/quint/src/IRprinting.ts @@ -195,9 +195,9 @@ export function sumToString(s: QuintSumType): string { return s.fields.fields .map((f: RowField) => { if (isTheUnit(f.fieldType)) { - ;`| ${f.fieldName}` + return `| ${f.fieldName}` } else { - ;`| ${f.fieldName}(${f.fieldType})` + return `| ${f.fieldName}(${typeToString(f.fieldType)})` } }) .join('\n') diff --git a/quint/test/IRprinting.test.ts b/quint/test/IRprinting.test.ts index cf398cfd4..4013ad7e9 100644 --- a/quint/test/IRprinting.test.ts +++ b/quint/test/IRprinting.test.ts @@ -3,6 +3,7 @@ import { assert } from 'chai' import { buildDef, buildExpression, buildModuleWithDefs, buildType } from './builders/ir' import { definitionToString, expressionToString, moduleToString, typeToString } from '../src/IRprinting' import { toScheme } from '../src/types/base' +import { QuintSumType, unitValue } from '../src' describe('moduleToString', () => { const quintModule = buildModuleWithDefs(['var S: Set[int]', 'val f = S.filter(x => x + 1)']) @@ -219,6 +220,22 @@ describe('typeToString', () => { assert.deepEqual(typeToString(type), expectedType) }) + it('pretty prints sum types', () => { + const type: QuintSumType = { + kind: 'sum', + fields: { + kind: 'row', + fields: [ + { fieldName: 'A', fieldType: { kind: 'int', id: 0n } }, + { fieldName: 'B', fieldType: unitValue(0n) }, + ], + other: { kind: 'empty' }, + }, + } + const expectedType = '| A(int)\n| B' + assert.deepEqual(typeToString(type), expectedType) + }) + it('pretty prints union types', () => { const type = buildType('| { tag: "A", a: int } | { tag: "B", b: str }') const expectedType = '| { tag: "A", a: int }\n| { tag: "B", b: str }'