Skip to content

Commit

Permalink
closes #33; fix wrong constexpr-implicit-const diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenwave committed Sep 22, 2024
1 parent 34be1d2 commit 1c84673
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions js/prose-decl.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ export class Explainer {
declarator.length === 1 && declarator[0].typ === 'id') {
return outerConst;
}
const last = declarator[declarator.length - 1];
if (last.typ === '*') {
return last.qualifiers && last.qualifiers.includes('const');
const first = declarator[Number(declarator[0].typ === 'id')];
if (first.typ === '*') {
return first.qualifiers && first.qualifiers.includes('const');
}
return false;
}
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ describe('Examples', function () {
});
});

code = 'constexpr int * const *';
describe(code, function () {
const {paragraphs, diagnostics} = codeToProse(code);
it('has correct prose', function () {
const expected = ['constexpr pointer to const pointer to int'];
assert.deepEqual(paragraphs, expected);
});
it('has constexpr-implicit-const diagnostic', function() {
assert.deepEqual(diagnostics, ['constexpr-implicit-const']);
});
});

code = 'constexpr int ** const';
describe(code, function () {
const {paragraphs, diagnostics} = codeToProse(code);
it('has correct prose', function () {
const expected = ['constexpr const pointer to pointer to int'];
assert.deepEqual(paragraphs, expected);
});
it('has no constexpr-implicit-const diagnostic', function() {
assert.ok(!diagnostics.includes('constexpr-implicit-const'));
});
});

code = 'constexpr int f()';
describe(code, function () {
const {paragraphs, diagnostics} = codeToProse(code);
Expand Down

0 comments on commit 1c84673

Please sign in to comment.