Skip to content

Commit

Permalink
Add fixes from previous code review
Browse files Browse the repository at this point in the history
These changes address the comments from
#1088

I had fixed all of these, but then merged the PR without pushing my
fixes.
  • Loading branch information
Shon Feder committed Aug 5, 2023
1 parent bab46d9 commit 0db831a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
6 changes: 3 additions & 3 deletions quint/src/IRprinting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ export function sumToString(s: QuintSumType): string {
return s.fields.fields
.map((f: RowField) => {
if (isTheUnit(f.fieldType)) {
return `| ${f.fieldName}`
return `${f.fieldName}`
} else {
return `| ${f.fieldName}(${typeToString(f.fieldType)})`
return `${f.fieldName}(${typeToString(f.fieldType)})`
}
})
.join('\n')
.join(' | ')
}

/**
Expand Down
2 changes: 1 addition & 1 deletion quint/src/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function prettyQuintType(type: QuintType): Doc {
return group([text('{ '), prettyRow(type.fields), text('}')])
}
case 'sum': {
return group([text('{ '), prettySumRow(type.fields), text('}')])
return prettySumRow(type.fields)
}
case 'union': {
const records = type.records.map(rec => {
Expand Down
2 changes: 1 addition & 1 deletion quint/src/parsing/ToIrListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class ToIrListener implements QuintListener {
// Check if we have an accompanying type, and if not, then synthesize the
// unit type.
//
// I.e., we interpert a variant `A` as `A({})`.
// I.e., we interpret a variant `A` as `A({})`.
if (poppedType === undefined) {
const id = this.idGen.nextId()
this.sourceMap.set(id, this.loc(ctx))
Expand Down
2 changes: 1 addition & 1 deletion quint/test/IRprinting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('typeToString', () => {
other: { kind: 'empty' },
},
}
const expectedType = '| A(int)\n| B'
const expectedType = 'A(int) | B'
assert.deepEqual(typeToString(type), expectedType)
})

Expand Down
41 changes: 24 additions & 17 deletions quint/test/parsing/quintParserFrontend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,31 @@ describe('parsing', () => {
})

it('parses sum types', () => {
const mod = `
module SumTypes {
type T =
| A
| B(int)
const sumTypeIrIsFormedCorrectly: (mod: string) => void = mod => {
const result = parsePhase1fromText(newIdGenerator(), mod, 'test')
assert(result.isRight())
const typeDef = result.value.modules[0].defs[0]
assert(typeDef.kind === 'typedef')
const sumType = typeDef.type!
assert(sumType.kind === 'sum')
const [variantA, variantB] = sumType.fields.fields
assert(variantA.fieldName === 'A')
assert(isTheUnit(variantA.fieldType))
assert(variantB.fieldName === 'B')
assert(variantB.fieldType.kind === 'int')
}
`
const result = parsePhase1fromText(newIdGenerator(), mod, 'test')
assert(result.isRight())
const typeDef = result.value.modules[0].defs[0]
assert(typeDef.kind === 'typedef')
const sumType = typeDef.type!
assert(sumType.kind === 'sum')
const [variantA, variantB] = sumType.fields.fields
assert(variantA.fieldName === 'A')
assert(isTheUnit(variantA.fieldType))
assert(variantB.fieldName === 'B')
assert(variantB.fieldType.kind === 'int')
sumTypeIrIsFormedCorrectly(`
module SumTypes {
type T =
| A
| B(int)
}
`)
sumTypeIrIsFormedCorrectly(`
module SumTypes {
type T = A | B(int)
}
`)
})
})

Expand Down

0 comments on commit 0db831a

Please sign in to comment.