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

Add check to disallow field in on_insert() #920

Merged
merged 5 commits into from
Sep 20, 2021
Merged

Conversation

waynelwarren
Copy link
Contributor

In the case of on_insert(tablename.fieldname), we are now disallowing the fieldname, as requested in GAIAPLAT-1396.

This emits an error message like:

/.../tests/gaiat/integration_test_expected_incorrect_table_name.ruleset:5:5: error: A field name may not be referenced in the on_insert statement. Use only a table name.
    on_insert(INC:incubator.max_temp)
    ^

If the caret should appear below max_temp, I can follow up with another commit for this.

Note that formatting changes in main.cpp are a persistent problem until the file has stable formatting. The changes are an attempt to do that.

@@ -9591,6 +9591,8 @@ def err_multi_anchor_tables : Error<
"A rule may not specify multiple tables or active fields from different tables "
"in 'on_' attributes (on_insert, on_change, or on_update). "
"Ensure that all your active field references belong to the same table.">;
def err_illegal_field_reference : Error<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would strike the name from the message. I.e. A field may not be referenced in 'on_insert'. The 'on_insert' attribute only accepts a table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's changed.

@@ -2477,6 +2477,12 @@ class rule_match_handler_t : public MatchFinder::MatchCallback
string table, field, tag;
if (parse_attribute(table_iterator, table, field, tag))
{
if (!field.empty())
{
gaiat::diag().emit(diag::err_illegal_field_reference);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the source location here is probably good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it that way.

Copy link
Contributor

@simone-gaia simone-gaia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -9591,6 +9591,8 @@ def err_multi_anchor_tables : Error<
"A rule may not specify multiple tables or active fields from different tables "
"in 'on_' attributes (on_insert, on_change, or on_update). "
"Ensure that all your active field references belong to the same table.">;
def err_illegal_field_reference : Error<
"A field may not be referenced in the 'on_insert' statement. The 'on_insert' attribute only accepts a table.">;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is on_insert a statement or an attribute? It's confusing to call it differently in the same error message. Maybe instead of statement or attribute, we should call it "clause"?

@waynelwarren waynelwarren merged commit 8a80490 into master Sep 20, 2021
@waynelwarren waynelwarren deleted the wayne/GAIAPLAT-1396 branch September 20, 2021 18:29
chuan pushed a commit that referenced this pull request Sep 23, 2021
* Add check to disallow field in on_insert()

* revert some clang-tidy changes to avoid diffs

* another attempt to fix formatting issues

* removed unnecessary line of code

* responding to PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants