Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow constructor calls of externs with abstract methods #3460

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,17 @@ TypeInference::checkExternConstructor(const IR::Node* errorPosition,
methodType = cloneWithFreshTypeVariables(methodType)->to<IR::Type_Method>();
CHECK_NULL(methodType);

if (errorPosition->is<IR::ConstructorCallExpression>()) {
for (auto m : ext->methods) {
if (m->isAbstract) {
typeError("%1%: extern type %2% with abstract methods cannot be instantiated"
" using a constructor call; consider using a declaration",
errorPosition, ext);
return nullptr;
}
}
}

auto args = new IR::Vector<IR::ArgumentInfo>();
size_t i = 0;
for (auto pi : *methodType->parameters->getEnumerator()) {
Expand Down
6 changes: 6 additions & 0 deletions testdata/p4_16_errors/issue3282.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern g {
g();
abstract void h();
}
package p(g a);
p(g()) main;
8 changes: 8 additions & 0 deletions testdata/p4_16_errors_outputs/issue3282.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern g {
g();
abstract void h();
}

package p(g a);
p(g()) main;

6 changes: 6 additions & 0 deletions testdata/p4_16_errors_outputs/issue3282.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue3282.p4(6): [--Werror=type-error] error: g: extern type g with abstract methods cannot be instantiated using a constructor call; consider using a declaration
p(g()) main;
^^^
issue3282.p4(1)
extern g {
^