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

ExplicitResultTypes: honor skipSimpleDefinitions on implicits #1698

Merged

Conversation

rvacaru
Copy link
Contributor

@rvacaru rvacaru commented Oct 28, 2022

Fixes #1628

The skipSimpleDefinitions configuration wasn't always applied correctly (specifically when members are implicit the configuration wasn't considered)

  • A unit test for this specific case was added
  • Old unit tests are fixed based on the default value of skipSimpleDefinitions or on the intent of the test

def matchesMemberKindAndVisibility: Boolean =
matchesMemberKind && matchesMemberVisibility
def matchesConfig: Boolean =
matchesMemberKind && matchesMemberVisibility && !matchesSimpleDefinition
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking at this line, wouldn't it make sense to have a && matchesSkipSimpleDefinition predicate instead, with the not (!) inside of the predicate itself?
At least to me it would look more readable, without having to worry on the content of the predicate

Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally like !matchesSimpleDefinition better - the "matches skip" is giving me headaches 😅

@@ -1,5 +1,6 @@
/*
rules = ExplicitResultTypes
ExplicitResultTypes.skipSimpleDefinitions = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the singletons in this tests are a Term.Ref, hence for this unit test to work the config needs to be overwritten

Comment on lines +5 to +7
val x = 42

implicit var y = 43
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Literal definitions are skipped, regardless if it's implicit or not, as expected

@@ -14,7 +14,7 @@ object ExplicitResultTypesShort {
implicit def z(x: Int): List[String] = Nil
implicit var zz: ListSet[String] = scala.collection.immutable.ListSet.empty[String]
implicit val FALSE: Any => Boolean = (x: Any) => false
implicit def tparam[T](e: T): T = e
implicit def tparam[T](e: T) = e
Copy link
Contributor Author

Choose a reason for hiding this comment

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

by default Term.Ref is skipped, hence this is the correct output

Comment on lines +22 to +23
implicit def D = 2
implicit def tparam[T](e: T) = e
Copy link
Contributor Author

Choose a reason for hiding this comment

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

by default Lit and Term.Ref are skipped, so this is the correct output

@@ -1,6 +1,7 @@
/*
rules = ExplicitResultTypes
ExplicitResultTypes.onlyImplicits = true
ExplicitResultTypes.skipSimpleDefinitions = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we're not testing skipSimpleDefinitions in this test, hence overwriting the default

Copy link
Collaborator

@bjaglin bjaglin left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

def matchesMemberKindAndVisibility: Boolean =
matchesMemberKind && matchesMemberVisibility
def matchesConfig: Boolean =
matchesMemberKind && matchesMemberVisibility && !matchesSimpleDefinition
Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally like !matchesSimpleDefinition better - the "matches skip" is giving me headaches 😅

@bjaglin bjaglin changed the title ExplicitResultTypes fix for skipSimpleDefinitions config ExplicitResultTypes: honor skipSimpleDefinitions on implicits Nov 2, 2022
@bjaglin bjaglin merged commit fc6337d into scalacenter:main Nov 14, 2022
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.

ExplicitResultTypes.isRuleCandidate evaluation improvements/fixes
2 participants