This is a pretty minimal reprex of a regression that might solve #6575 and was extracted from the tests in {DTwrappers}:
https://github.com/cran/DTwrappers/blob/e730e04e9164aa333339955375d6c225f7609fcc/tests/testthat/test-dtwrappers.R#L11-L17
x = data.frame(a = 1)
e = environment()
foo = function() {
setDT(get('x', envir=e))
}
foo()
is.data.table(x)
## 1.16.4
# [1] TRUE
## current master
# [1] FALSE