Skip to content

[Compile Warnings As Errors] WordPress Module - Resolve Type/Cast/When Warnings#17291

Merged
ParaskP7 merged 10 commits intotrunkfrom
analysis/wordpress-main-type-cast-when-warnings
Oct 11, 2022
Merged

[Compile Warnings As Errors] WordPress Module - Resolve Type/Cast/When Warnings#17291
ParaskP7 merged 10 commits intotrunkfrom
analysis/wordpress-main-type-cast-when-warnings

Conversation

@ParaskP7
Copy link
Copy Markdown
Contributor

@ParaskP7 ParaskP7 commented Oct 10, 2022

Parent: #17173
Partially Closes: #17181

This PR resolves one part of all Type/Cast/When related warnings for the WordPress module, and in this part, specific to the main source:

Type Related (44):

  • 4 x Unsafe use of a nullable receiver of type Xyz?
  • 13 x Type mismatch: inferred type is Xyz? but Xyz was expected
  • 4 x Elvis operator (?:) always returns the left operand of non-nullable type Xyz
  • 4 x The corresponding parameter in the supertype 'Xyz' is named 'xyz'. This may cause problems when calling this function with named arguments.
  • 11 x ents. (4) Unnecessary non-null assertion (!!) on a non-null receiver of type Xyz
  • 18 x Unnecessary safe call on a non-null receiver of type Xyz. This expression will have nullable type in future releases

Cast Related (5):

  • 4 x Unchecked cast: Xyz to Xyz
  • 1 x This cast can never succeed

When Related (26):

  • 26 x Non exhaustive 'when' statements on xyz will be prohibited in 1.7, add 'Xyz', 'Xyz' branch(es) or 'else' branch instead

Warnings Resolution List:

Warnings Suppression List:

Refactor List:


PS: @ovitrif I added you as the main reviewer, that is, in addition to @wordpress-mobile/apps-infrastructure team itself, but randomly, since I want someone from the WordPress Android team to primarily sign-off on that change. 🥇

FYI: I am going to randomly add more of you in those PRs that will follow, just so you become more aware of this change and how close we are on enabling allWarningsAsErrors by default everywhere. 🎉


To test:

  • There is nothing much to test here.
  • Verifying that all the CI checks are successful should be enough.
  • However, if you want to be thorough about reviewing this change, you could quickly smoke test both, the WordPress and Jetpack apps, and see if they are both working as expected.

Regression Notes

  1. Potential unintended areas of impact

N/A

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

See To test section above.

  1. What automated tests I added (or what prevented me from doing so)

N/A


PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Both these functions are unused and/or contains compile warnings that
needs resolving.

Warning Messages:
- "Unsafe use of a nullable receiver of type Package?"
- "Type mismatch: inferred type is String? but String was expected"

Instead of resolving any compile warnings related to unused code, it is
better to remove such code and stop maintaining it altogether.

In the future, and if need be, this code can be added back, with an
explicit comment that it shouldn't be removed anymore, thus suppressing
it with an '@Suppress("unused")' annotation, along with a reasoning
behind keeping unused code like that.
Warning Message: "Unsafe use of a nullable receiver of type Xyz?"

After resolving some of the compile related type warnings, some Detekt
baseline related warnings needed to be removed and suppressed closer to
source because the lines on those classes got changed.
Warning Message: "Type mismatch: inferred type is Xyz?
but Xyz was expected"

After resolving some of the compile related type warnings, some Detekt
baseline related warnings needed to be removed and suppressed closer to
source because the lines on those classes got changed.
Warning Message: "Elvis operator (?:) always returns the left operand of
non-nullable type Xyz"
Warning Message: "The corresponding parameter in the supertype 'Xyz' is
named 'xyz'. This may cause problems when calling this function with
named arguments."
Warning Message: "Unnecessary non-null assertion (!!) on a non-null
receiver of type AppComponent"
Warning Message: "Unnecessary safe call on a non-null receiver of type
Xyz. This expression will have nullable type in future releases"
Warning Message: "Unchecked cast: Xyz to Xyz"

These type warnings are suppressed, that is, instead of being resolved,
since a resolution would require a proper investigation and testing. As
such, it might be best to ignore those as out of scope, for now, and so
as to not introduce any breaking changes to these functionalities
overall.
Warning Message: "This cast can never succeed"

This type warning is suppressed, that is, instead of being resolved,
since a resolution would require a proper investigation and testing.
As such, it might be best to ignore this as out of scope, for now, and
so as to not introduce any breaking changes to this functionality
overall.
Warning Message: "Non exhaustive 'when' statements on enum will be
prohibited in 1.7, add 'Xyz', 'Xyz' branch(es) or 'else' branch instead"

You will notice that I optimized the imports on all those when
statements and the imports they were using because one or no import is
always better than having multiple imports for no particular reason.
Also, having the extra information like 'FormattableRangeType.SITE'
instead of plain 'SITE' is usually better for readability purposes as
the reader will immediately understand that this 'SITE' is
'FormattableRangeType' related, without the need to navigate to the
'SITE' in order to understand when that is coming from.
@ParaskP7 ParaskP7 added this to the 21.0 milestone Oct 10, 2022
@ParaskP7 ParaskP7 requested review from a team and ovitrif October 10, 2022 12:55
@ParaskP7 ParaskP7 self-assigned this Oct 10, 2022
@ParaskP7 ParaskP7 changed the title [Compile Warnings As Errors] WordPress Module - Resolve Type Warnings [Compile Warnings As Errors] WordPress Module - Resolve Type/Cast/When Warnings Oct 10, 2022
@wpmobilebot
Copy link
Copy Markdown
Contributor

Jetpack📲 You can test these changes on Jetpack by downloading jetpack-installable-build-pr17291-f15bfc9.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppJetpack
Build FlavorJalapeno
Build TypeDebug
Commitf15bfc9
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@wpmobilebot
Copy link
Copy Markdown
Contributor

WordPress📲 You can test these changes on WordPress by downloading wordpress-installable-build-pr17291-f15bfc9.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppWordPress
Build FlavorJalapeno
Build TypeDebug
Commitf15bfc9
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

Copy link
Copy Markdown
Contributor

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

The code changes look consistent to me and smoke testing both apps shows no regression ✅ .

Thank you for your effort on this project @ParaskP7 🙇 🥇 🎉

@ParaskP7
Copy link
Copy Markdown
Contributor Author

This is awesome, thank you so much for reviewing and testing this PR @ovitrif, you rock! 🙇 ❤️ 🚀

Thank you for your effort on #17181 @ParaskP7 🙇 🥇 🎉

Back at you Ovi for all your support and help with the PRs! 🙇 🙏 🥇

@ParaskP7 ParaskP7 merged commit 731ee6a into trunk Oct 11, 2022
@ParaskP7 ParaskP7 deleted the analysis/wordpress-main-type-cast-when-warnings branch October 11, 2022 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler Warnings as Errors - WordPress Module

3 participants