Skip to content

Commit d3e19ce

Browse files
authored
Merge pull request #39 from t-kalinowski/case-sensitive-checks
Case sensitive checks
2 parents 3a14cca + f6ef0de commit d3e19ce

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

R/preprocess-lang.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ whole_doubles_to_ints <- function(x) {
3737
}
3838
walker(x)
3939
}
40+
41+
42+
substitute_unique_case_insensitive_symbols <- function(x) {
43+
# TODO: would be nice to fix case-insenstive name clashes
44+
# with automatic substitutions. Would be a little involved since
45+
# substitute will not replace tag names in a call, e.g.,
46+
# declare(type(<NAME> = ...)), NAME would need to be manually replaced.
47+
stopifnot(is.function(x))
48+
nms <- unique(c(all.names(body(x), names(formals(x)))))
49+
stop("not yet implemented")
50+
}

R/quick.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ check_all_var_names_valid <- function(fun) {
236236
glue_collapse(invalid, ", ", last = ", and ")
237237
)
238238
}
239+
240+
case_clashes <- nms[is_duplicate(tolower(nms))]
241+
if (length(case_clashes)) {
242+
stop(
243+
"Fortran is case-insensitive; these names conflict when case is ignored: ",
244+
glue_collapse(glue::backtick(case_clashes), ", ", last = " and ")
245+
)
246+
}
239247
}
240248

241249

@@ -247,3 +255,9 @@ make_unique_name <- local({
247255
paste0(prefix, i <<- i + 1L)
248256
}
249257
})
258+
259+
is_duplicate <- function(x) {
260+
out <- duplicated(x) | duplicated(x, fromLast = TRUE)
261+
names(out) <- names(x)
262+
out
263+
}

tests/testthat/test-errors.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_that("case-sensitive variable name clashes", {
2+
expect_error(regexp = "case-insensitive.+`j`.+`J`", {
3+
quick(function(j) {
4+
declare(type(j = integer(1)))
5+
J <- double(length = j)
6+
J
7+
})
8+
})
9+
})

0 commit comments

Comments
 (0)