Skip to content

Commit

Permalink
v1800-2023: extern constraint block override specifiers must match th…
Browse files Browse the repository at this point in the history
…e prototype declaration
  • Loading branch information
MikePopoloski committed May 11, 2024
1 parent adc771a commit 3b0116d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/diagnostics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ error InvalidRandType "{} is not a valid type for a '{}' property"
error InvalidMethodOverride "cannot override built-in method '{}'"
error InvalidRandomizeOverride "override for '{}' should be a public non-static function that returns void and takes no parameters"
error MismatchStaticConstraint "mismatch of 'static' keyword between constraint prototype and declaration"
error MismatchConstraintSpecifiers "mismatch of override specifiers between constraint prototype and declaration"
error DPIRefArg "DPI subroutines cannot have 'ref' arguments"
error DPIPureArg "DPI imports marked 'pure' cannot have 'output' or 'inout' arguments"
error DPIPureReturn "DPI imports marked 'pure' cannot return 'void'"
Expand Down
10 changes: 10 additions & 0 deletions source/ast/symbols/ClassSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,16 @@ const Constraint& ConstraintBlockSymbol::getConstraints() const {
diag.addNote(diag::NoteDeclarationHere, location);
}

bitmask<ConstraintBlockFlags> declFlags;
addSpecifierFlags(cds.specifiers, declFlags);

if (declFlags != (flags & (ConstraintBlockFlags::Initial | ConstraintBlockFlags::Extends |
ConstraintBlockFlags::Final))) {
auto& diag = outerScope.addDiag(diag::MismatchConstraintSpecifiers,
cds.name->getLastToken().location());
diag.addNote(diag::NoteDeclarationHere, location);
}

constraint = &Constraint::bind(*cds.block, context);
return *constraint;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/unittests/ast/ClassTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3334,3 +3334,24 @@ endclass
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::BadSolveBefore);
}

TEST_CASE("v1800-2023: extern constraint blocks must match specifiers") {
auto options = optionsFor(LanguageVersion::v1800_2023);
auto tree = SyntaxTree::fromText(R"(
class A;
extern constraint :initial a;
extern constraint :final b;
endclass
constraint A::a {}
constraint :final A::b {}
)",
options);

Compilation compilation(options);
compilation.addSyntaxTree(tree);

auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::MismatchConstraintSpecifiers);
}

0 comments on commit 3b0116d

Please sign in to comment.