Skip to content

Add check for redundant attributes (for now: redundant access specifier)#441

Merged
1 commit merged intodlang-community:masterfrom
wilzbach:redundant_attribute
Jun 15, 2017
Merged

Add check for redundant attributes (for now: redundant access specifier)#441
1 commit merged intodlang-community:masterfrom
wilzbach:redundant_attribute

Conversation

@wilzbach
Copy link
Member

When I started to write this check, it was mainly to avoid redundant access specifiers like:

private:
   private int foo;

However, I realized that it can work with any kind of attribute, e.g.

@safe:
   @safe void foo() {}

or

@myCustomUDA {
    @myCustomUDA void foo() {}
} 

However, for now I lack the time to properly test all attribute combination, so I wrote generic code, but only enabled it for access specifier. It shouldn't be too hard to extend it to all attributes later.

@ghost
Copy link

ghost commented Jun 12, 2017

I'd like to see a test for

private:
public int a;
private: // should warn here

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

style + use same name as in the grammar

{
auto token = attr.attribute;
addErrorMessage(token.line, token.column, KEY,
text("same access specifier used as defined on line ",
Copy link

@ghost ghost Jun 12, 2017

Choose a reason for hiding this comment

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

"access specifier" is inaccurate, it's called a visibility attribute.
If you add support for other attributes you'll have to think to use the correct term too.

void addAttribute(const Attribute attr)
{
removeOverwrite(attr);
if (checkAttribute(attr)) {
Copy link

Choose a reason for hiding this comment

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

please don't blend the brace styles. same remark plenty of times !

@ghost
Copy link

ghost commented Jun 12, 2017

small remark for the future: you can push the feature branch directly on dlang-community. It's easier for the reviewers to pull the branch on their clone.

@wilzbach
Copy link
Member Author

I'd like to see a test for

Added. Btw dlang/phobos#5477 contains all found instances in Phobos, but as mentioned it doesn't check all attributes (for now).

style + use same name as in the grammar

Fixed. Sorry.

small remark for the future: you can push the feature branch directly on dlang-community. It's easier for the reviewers to pull the branch on their clone.

Okay. I will do so next time.
Btw you can rather easily pull a PR with this git config:

[remote "upstream"]
	fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*

(or master if you don't use an upstream here).

and then e.g. git checkout pr/441

@ghost
Copy link

ghost commented Jun 12, 2017

I suspected the current failure. It's on the test i asked you to add.

@wilzbach
Copy link
Member Author

I suspected the current failure. It's on the test i asked you to add.

Hmm are you sure?
AFAICT I just forgot to adjust the line numbers after changing the brace style?

@ghost
Copy link

ghost commented Jun 12, 2017

AFAICT I just forgot to adjust the line numbers after changing the brace style?

Right.

Appveyor icon is still there ?

@wilzbach
Copy link
Member Author

wilzbach commented Jun 12, 2017

Appveyor icon is still there ?

I think GH isn't that smart - it will just be gone for new PRs ...

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

looks good now.

@wilzbach wilzbach force-pushed the redundant_attribute branch from fc7b5d7 to e06ddb2 Compare June 14, 2017 22:21
@wilzbach
Copy link
Member Author

(rebased to master)

@ghost
Copy link

ghost commented Jun 14, 2017

Do you want to use this on phobos ASAP ? For me it's quite mergeable in the current state. Also you didn't touch it last 2 days, which means that it's also okay for you.

@wilzbach
Copy link
Member Author

Do you want to use this on phobos ASAP ?

I currently have other goals, but eventually at some point in the future, yes.
But I haven't had time to fix dlang/phobos#5477, so there's no need to hurry.
I just saw the merge error here ...

For me it's quite mergeable in the current state. Also you didn't touch it last 2 days, which means that it's also okay for you.

I eventually want to make it work with all kind of attributes, but unfortunately not in this month or in the foreseeable future.

@ghost
Copy link

ghost commented Jun 14, 2017

I eventually want to make it work with all kind of attributes

There's chance that the same check for all the attributes require much more work and will not be compatible with the current structure. IIRC for a @safe struct{} safety is propagated to functions templates too, so processing is different.

@ghost ghost merged commit 7649216 into dlang-community:master Jun 15, 2017
@wilzbach wilzbach deleted the redundant_attribute branch August 20, 2020 01:00
This pull request was closed.
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.

1 participant