Skip to content

Commit a4a9ebd

Browse files
authored
do not include deleted params in header signature (#492)
1 parent 3a4b91d commit a4a9ebd

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

src/Clause.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,18 @@ function parseType(type: string, offset: number): Type {
402402

403403
function parsedHeaderToSignature(parsedHeader: ParsedHeader): Signature {
404404
const ret = {
405-
parameters: parsedHeader.params.map(p => ({
406-
name: p.name,
407-
type: p.type == null ? null : parseType(p.type, p.typeOffset),
408-
})),
409-
optionalParameters: parsedHeader.optionalParams.map(p => ({
410-
name: p.name,
411-
type: p.type == null ? null : parseType(p.type, p.typeOffset),
412-
})),
405+
parameters: parsedHeader.params
406+
.filter(p => p.wrappingTag !== 'del')
407+
.map(p => ({
408+
name: p.name,
409+
type: p.type == null ? null : parseType(p.type, p.typeOffset),
410+
})),
411+
optionalParameters: parsedHeader.optionalParams
412+
.filter(p => p.wrappingTag !== 'del')
413+
.map(p => ({
414+
name: p.name,
415+
type: p.type == null ? null : parseType(p.type, p.typeOffset),
416+
})),
413417
return:
414418
parsedHeader.returnType == null
415419
? null

test/typecheck.js

+43
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,49 @@ describe('signature agreement', async () => {
846846
);
847847
});
848848

849+
it("<del>'d params don't contribute to signature", async () => {
850+
let biblio = await getBiblio(`
851+
<emu-clause id="del-complex" type="abstract operation">
852+
<h1>
853+
DelExample (
854+
<del>_x_: unknown,</del>
855+
_y_: unknown,
856+
<ins>_z_: unknown,</ins>
857+
<ins>_w_: unknown,</ins>
858+
): unknown
859+
</h1>
860+
<dl class="header"></dl>
861+
</emu-clause>
862+
`);
863+
864+
await assertLint(
865+
positioned`
866+
<emu-alg>
867+
1. Return ${M}DelExample(*"x"*, *"y"*).
868+
</emu-alg>
869+
`,
870+
{
871+
ruleId: 'typecheck',
872+
nodeType: 'emu-alg',
873+
message: 'DelExample takes 3 arguments, but this invocation passes 2',
874+
},
875+
{
876+
extraBiblios: [biblio],
877+
}
878+
);
879+
880+
await assertLintFree(
881+
`
882+
<emu-alg>
883+
1. Return DelExample(*"y"*, *"z"*, *"w"*).
884+
</emu-alg>
885+
`,
886+
{
887+
extraBiblios: [biblio],
888+
}
889+
);
890+
});
891+
849892
it('negative', async () => {
850893
await assertLintFree(
851894
`

0 commit comments

Comments
 (0)