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

typeChecker: make error message less confusing #3152

Merged
merged 1 commit into from
Mar 25, 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
6 changes: 4 additions & 2 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2935,7 +2935,9 @@ const IR::Node* TypeInference::postorder(IR::Member* expression) {
}

if (type->is<IR::Type_StructLike>()) {
cstring typeStr = "structure ";
if (type->is<IR::Type_Header>() || type->is<IR::Type_HeaderUnion>()) {
typeStr = "";
if (inMethod && (member == IR::Type_Header::isValid)) {
// Built-in method
auto type = new IR::Type_Method(
Expand Down Expand Up @@ -2968,8 +2970,8 @@ const IR::Node* TypeInference::postorder(IR::Member* expression) {
auto stb = type->to<IR::Type_StructLike>();
auto field = stb->getField(member);
if (field == nullptr) {
typeError("Field %1% is not a member of structure %2%",
expression->member, stb);
typeError("Field %1% is not a member of %2%%3%",
expression->member, typeStr, stb);
return expression;
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_errors_outputs/issue561-1.p4-stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ issue561-1.p4(29)
issue561-1.p4(19)
header_union U {
^
issue561-1.p4(30): [--Werror=type-error] error: Field setValid is not a member of structure header_union U
issue561-1.p4(30): [--Werror=type-error] error: Field setValid is not a member of header_union U
u.setValid(); // no such method
^^^^^^^^
issue561-1.p4(19)
Expand Down