Visitar URL original
remove redundant inline casts by erik-krogh · Pull Request #6994 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20211101022612/https://github.com/github/codeql/pull/6994
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

remove redundant inline casts #6994

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
@erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Oct 28, 2021 •

The patch was written automatically by a tool.

Removes inline casts where:

  • the expression is cast to the type the expression already has, or:
  • the inline cast is one side of an equality comparison, where the other side already has the type.
@erik-krogh erik-krogh marked this pull request as ready for review Oct 28, 2021
@erik-krogh erik-krogh requested review from as code owners Oct 28, 2021
Copy link
Contributor

@geoffw0 geoffw0 left a comment

CPP results LGTM (in a few cases it took a moment to see why, but the query appears to have got it right every time).

Copy link
Contributor

@nickrolfe nickrolfe left a comment

Ruby changes look good 👍

Copy link
Contributor

@yoff yoff left a comment

Python changes look correct.
I do wonder if the cases in Django.qll, Flask.qll, and CallArgs.qll are intentional for readability. I suspect @RasmusWL has an opinion on this.
(But I would be fine with merging as is. Only the two in CallArgs.qll really guide the reasoning in my opinion, and they live in a very small context.)

Copy link
Contributor

@aschackmull aschackmull left a comment

Java changes LGTM.

Copy link
Member

@RasmusWL RasmusWL left a comment

I would like to keep the redundant casts in

  • python/ql/lib/semmle/python/frameworks/Tornado.qll
  • python/ql/lib/semmle/python/frameworks/Flask.qll
  • python/ql/lib/semmle/python/frameworks/Django.qll

since they aid me in remembering how stuff works, without having to explore other predicates to see which types they have. Theoretically it should be possible for me to remember how Class.getParent() works, but it just doesn't stick.

@erik-krogh erik-krogh dismissed stale reviews from aschackmull, nickrolfe, and geoffw0 via 0897b00 Oct 29, 2021
@erik-krogh
Copy link
Contributor Author

@erik-krogh erik-krogh commented Oct 29, 2021

I would like to keep the redundant casts in...

I've reverted that part.


I also removed more redundant casts (from a suggestion by @MathiasVP).
Simplified example:

predicate foo(AddExpr add) { ... }

from Expr e
where foo(e.(AddExpr)) // <- redundant
select e

Copy link
Contributor

@nickrolfe nickrolfe left a comment

AFAICT there were no new Ruby changes, so 👍

@jbj
Copy link
Contributor

@jbj jbj commented Oct 29, 2021

I also removed more redundant casts (from a suggestion by @MathiasVP). Simplified example:

predicate foo(AddExpr add) { ... }

from Expr e
where foo(e.(AddExpr)) // <- redundant
select e

I've occasionally introduced such casts on purpose. They serve as documentation. If the distance between foo and its caller is large, the reader can't easily tell that e is easily restricted to AddExpr unless a redundant cast is added.

If the types were the other way around, I'd agree that the cast would be redundant. For example,

predicate foo(Expr add) { ... }

from AddExpr e
where foo(e.(AddExpr)) // <- redundant
select e

Copy link
Member

@RasmusWL RasmusWL left a comment

👍 for Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment