Skip to content

Commit

Permalink
closes #32; fix missing diagnostic for duplicate qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenwave committed Sep 22, 2024
1 parent 8cc3ecd commit 34be1d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ <h2>C Declarations &amp; printf/scanf &#10132; Prose</h2>
<div id="d-restrict-qualified-function" class="d-error" hidden>
<span>Functions may not be restrict-qualified</span>
</div>
<div id="d-duplicate-pointer-qualifier" class="d-error" hidden>
<span>Duplicate qualifier on pointer</span>
</div>
<div id="d-duplicate-function-qualifier" class="d-error" hidden>
<span>Duplicate qualifier on function</span>
</div>
<div id="d-zero-size-array" class="d-warning" hidden>
<span>Zero-size arrays are a non-standard extension</span>
</div>
Expand Down
14 changes: 14 additions & 0 deletions js/prose-decl.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,18 @@ export class Explainer {
}
}

/**

Check failure on line 366 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing JSDoc @returns for function

Check failure on line 366 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing JSDoc @returns for function
* Checks whether there are duplicate qualifiers in the given list
* @param {string[]} qualifiers

Check failure on line 368 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing JSDoc parameter description for 'qualifiers'

Check failure on line 368 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing JSDoc parameter description for 'qualifiers'
* @param {'function' | 'pointer'} context

Check failure on line 369 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing JSDoc parameter description for 'context'

Check failure on line 369 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing JSDoc parameter description for 'context'
*/
checkForDuplicateQualifiers(qualifiers, context) {
const withoutDuplicates = new Set(qualifiers.map(q => q === '_Atomic' ? 'atomic' : q))

Check failure on line 372 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 372 in js/prose-decl.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
if (withoutDuplicates.size !== qualifiers.length) {
this.showDiagnostic(`duplicate-${context}-qualifier`);
}
}

/**
* Throws if there is misuse of specifiers in the declaration specifier
* sequence, depending on the provided kind of context.
Expand Down Expand Up @@ -508,6 +520,7 @@ export class Explainer {
break;
}
case '*': {
this.checkForDuplicateQualifiers(d.qualifiers, 'pointer');
const q = d.qualifiers
.sort(Explainer.compareSpecifiers)
.map(Explainer.remapSpecifierTextForReadability)
Expand Down Expand Up @@ -598,6 +611,7 @@ export class Explainer {
this.showDiagnostic('empty-function-parameters');
}

this.checkForDuplicateQualifiers(d.qualifiers, 'function');
let overrideFinal = d.qualifiers[d.qualifiers.length - 1];
if (!['override', 'final'].includes(overrideFinal)) {
overrideFinal = undefined;
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,20 @@ describe('Examples', function () {
assert.ok(!diagnostics.includes('constexpr-implicit-const'));
});
});

code = 'void() const const';
describe(code, function () {
const diagnostics = codeToProse(code).diagnostics;
it('rejects duplicate qualifiers on function', function() {
assert.ok(diagnostics.includes('duplicate-function-qualifier'));
});
});

code = 'void * const const';
describe(code, function () {
const diagnostics = codeToProse(code).diagnostics;
it('rejects duplicate qualifiers on pointer', function() {
assert.ok(diagnostics.includes('duplicate-pointer-qualifier'));
});
});
});

0 comments on commit 34be1d2

Please sign in to comment.