Skip to content

Commit

Permalink
Forbid externs as tuple arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
  • Loading branch information
Mihai Budiu committed Dec 2, 2022
1 parent 0d94633 commit 0b30c0b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,9 @@ const IR::Node* TypeInference::postorder(IR::Type_List* type) {
const IR::Node* TypeInference::postorder(IR::Type_Tuple* type) {
for (auto field : type->components) {
auto fieldType = getTypeType(field);
if (fieldType->is<IR::IContainer>() || fieldType->is<IR::Type_ArchBlock>()) {
if (auto spec = fieldType->to<IR::Type_SpecializedCanonical>()) fieldType = spec->baseType;
if (fieldType->is<IR::IContainer>() || fieldType->is<IR::Type_ArchBlock>() ||
fieldType->is<IR::Type_Extern>()) {
typeError("%1%: not supported as a tuple field", field);
return type;
}
Expand Down
17 changes: 17 additions & 0 deletions testdata/p4_16_errors/issue3750-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extern ct {
void apply();
}

extern E<T> {
void apply();
}

void f(tuple<ct> t)
{
t[0].apply();
}

void g(tuple<E<bit<32>>> t)
{
t[0].apply();
}
14 changes: 14 additions & 0 deletions testdata/p4_16_errors_outputs/issue3750-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extern ct {
void apply();
}

extern E<T> {
void apply();
}

void f(tuple<ct> t) {
t[0].apply();
}
void g(tuple<E<bit<32>>> t) {
t[0].apply();
}
6 changes: 6 additions & 0 deletions testdata/p4_16_errors_outputs/issue3750-1.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue3750-1.p4(9): [--Werror=type-error] error: ct: not supported as a tuple field
void f(tuple<ct> t)
^^
issue3750-1.p4(14): [--Werror=type-error] error: E<bit<32>>: not supported as a tuple field
void g(tuple<E<bit<32>>> t)
^^^^^^^^^^

0 comments on commit 0b30c0b

Please sign in to comment.