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

false positive in nested vector_logic_linter usage when '&' is a method #1453

Closed
MichaelChirico opened this issue Jul 17, 2022 · 1 comment · Fixed by #2371
Closed

false positive in nested vector_logic_linter usage when '&' is a method #1453

MichaelChirico opened this issue Jul 17, 2022 · 1 comment · Fixed by #2371
Labels
false-positive code that shouldn't lint, but does

Comments

@MichaelChirico
Copy link
Collaborator

MichaelChirico commented Jul 17, 2022

& and | are generics, so methods can be defined for which the output is not logical.

This is the case for base octmode class which has an & method to do bitwise-and (much like C/Python's &) and returns octmode (see ?"&.octmode"). As seen in base R:

https://github.com/r-devel/r-svn/blob/9bcb4bef2979e608804fb37ab6471b4894bfa2b2/src/library/utils/R/tar.R#L497

if (is.null(extra_flags) && grepl("/(configure|cleanup)$", f) &&
    (mode & "111") != as.octmode("111")) {
    #     ^ marked as a lint
    warning(gettextf("file '%s' did not have execute permissions: corrected", f), domain = NA, call. = FALSE)
    mode <- mode | "111"
}

The giveaway here is that a comparison operator is used in the <expr> above & -- IINM vector_logic_linter() assumes parent infixes will be &/&&/|/||.

My first instinct was just to call this a known edge case & move on, because in general we can't swap && for all methods of &, but for this particular method we can detect it's fine statically.

@MichaelChirico MichaelChirico added the false-positive code that shouldn't lint, but does label Jul 17, 2022
@MichaelChirico
Copy link
Collaborator Author

Very similar case seen in sf:

https://github.com/r-spatial/sf/blob/3362108a005ab77ba83953430dbaa6edf4b26075/R/wkb.R#L128-L132

zm = if ((info & as.raw(12)) == as.raw(12))
  "XYZM"
else if (info & as.raw(8))
  "XYZ"
else if (info & as.raw(4))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant