Skip to content

Commit

Permalink
do not include deleted params in header signature (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored Oct 17, 2022
1 parent 3a4b91d commit a4a9ebd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Clause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,18 @@ function parseType(type: string, offset: number): Type {

function parsedHeaderToSignature(parsedHeader: ParsedHeader): Signature {
const ret = {
parameters: parsedHeader.params.map(p => ({
name: p.name,
type: p.type == null ? null : parseType(p.type, p.typeOffset),
})),
optionalParameters: parsedHeader.optionalParams.map(p => ({
name: p.name,
type: p.type == null ? null : parseType(p.type, p.typeOffset),
})),
parameters: parsedHeader.params
.filter(p => p.wrappingTag !== 'del')
.map(p => ({
name: p.name,
type: p.type == null ? null : parseType(p.type, p.typeOffset),
})),
optionalParameters: parsedHeader.optionalParams
.filter(p => p.wrappingTag !== 'del')
.map(p => ({
name: p.name,
type: p.type == null ? null : parseType(p.type, p.typeOffset),
})),
return:
parsedHeader.returnType == null
? null
Expand Down
43 changes: 43 additions & 0 deletions test/typecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,49 @@ describe('signature agreement', async () => {
);
});

it("<del>'d params don't contribute to signature", async () => {
let biblio = await getBiblio(`
<emu-clause id="del-complex" type="abstract operation">
<h1>
DelExample (
<del>_x_: unknown,</del>
_y_: unknown,
<ins>_z_: unknown,</ins>
<ins>_w_: unknown,</ins>
): unknown
</h1>
<dl class="header"></dl>
</emu-clause>
`);

await assertLint(
positioned`
<emu-alg>
1. Return ${M}DelExample(*"x"*, *"y"*).
</emu-alg>
`,
{
ruleId: 'typecheck',
nodeType: 'emu-alg',
message: 'DelExample takes 3 arguments, but this invocation passes 2',
},
{
extraBiblios: [biblio],
}
);

await assertLintFree(
`
<emu-alg>
1. Return DelExample(*"y"*, *"z"*, *"w"*).
</emu-alg>
`,
{
extraBiblios: [biblio],
}
);
});

it('negative', async () => {
await assertLintFree(
`
Expand Down

0 comments on commit a4a9ebd

Please sign in to comment.