Skip to content

Commit

Permalink
Fix incorrect overload resolution for specialized (package) types (p4…
Browse files Browse the repository at this point in the history
…lang#3412)

Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
Mihai Budiu authored and rst0git committed Jul 1, 2022
1 parent 71f8b74 commit 4a462fa
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontends/common/resolveReferences/resolveReferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const IR::Vector<IR::Argument> *ResolutionContext::methodArguments(cstring name)
if (auto type = decl->type->to<IR::Type_Name>()) {
if (type->path->name == name)
return decl->arguments; }
if (auto ts = decl->type->to<IR::Type_Specialized>()) {
if (ts->baseType->path->name == name)
return decl->arguments; }
break; }
if (ctxt->node->is<IR::Expression>() || ctxt->node->is<IR::Type>())
ctxt = ctxt->parent;
Expand Down
14 changes: 14 additions & 0 deletions testdata/p4_16_samples/issue3379-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parser mypt<t>(in t tt);

parser MyParser1(in bit tt) {
state start {
transition select(tt) {
0: accept;
_: reject;
}
}
}

package mypackaget<t>(mypt<t> t2);
package mypackaget<t>(mypt<t> t1, mypt<t> t2);
mypackaget<bit>(MyParser1()) t4;
15 changes: 15 additions & 0 deletions testdata/p4_16_samples/issue3379.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parser mypt<t>(in t tt);

parser MyParser1(in bit tt) {
state start {
transition select(tt) {
0: accept;
_: reject;
}
}
}

typedef bit t;
package mypackaget(mypt<t> t2);
package mypackaget(mypt<t> t1, mypt<t> t2);
mypackaget(MyParser1()) t4;
14 changes: 14 additions & 0 deletions testdata/p4_16_samples_outputs/issue3379-1-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parser mypt<t>(in t tt);
parser MyParser1(in bit<1> tt) {
state start {
transition select(tt) {
1w0: accept;
default: reject;
}
}
}

package mypackaget<t>(mypt<t> t2);
package mypackaget<t>(mypt<t> t1, mypt<t> t2);
mypackaget<bit<1>>(MyParser1()) t4;

Empty file.
14 changes: 14 additions & 0 deletions testdata/p4_16_samples_outputs/issue3379-1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parser mypt<t>(in t tt);
parser MyParser1(in bit<1> tt) {
state start {
transition select(tt) {
0: accept;
default: reject;
}
}
}

package mypackaget<t>(mypt<t> t2);
package mypackaget<t>(mypt<t> t1, mypt<t> t2);
mypackaget<bit<1>>(MyParser1()) t4;

4 changes: 4 additions & 0 deletions testdata/p4_16_samples_outputs/issue3379-1.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
issue3379-1.p4(14): [--Wwarn=unused] warning: t4: unused instance
mypackaget<bit>(MyParser1()) t4;
^^
[--Wwarn=missing] warning: Program does not contain a `main' module
15 changes: 15 additions & 0 deletions testdata/p4_16_samples_outputs/issue3379-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parser mypt<t>(in t tt);
parser MyParser1(in bit<1> tt) {
state start {
transition select(tt) {
1w0: accept;
default: reject;
}
}
}

typedef bit<1> t;
package mypackaget(mypt<t> t2);
package mypackaget(mypt<t> t1, mypt<t> t2);
mypackaget(MyParser1()) t4;

Empty file.
15 changes: 15 additions & 0 deletions testdata/p4_16_samples_outputs/issue3379.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parser mypt<t>(in t tt);
parser MyParser1(in bit<1> tt) {
state start {
transition select(tt) {
0: accept;
default: reject;
}
}
}

typedef bit<1> t;
package mypackaget(mypt<t> t2);
package mypackaget(mypt<t> t1, mypt<t> t2);
mypackaget(MyParser1()) t4;

4 changes: 4 additions & 0 deletions testdata/p4_16_samples_outputs/issue3379.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
issue3379.p4(15): [--Wwarn=unused] warning: t4: unused instance
mypackaget(MyParser1()) t4;
^^
[--Wwarn=missing] warning: Program does not contain a `main' module

0 comments on commit 4a462fa

Please sign in to comment.