Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

Go: count os.ExpandEnv, os.TempDir and the user dirs as environment reads (#1416)

jakalijeydd2256c686c3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f610b01..20c5bf99 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -267,6 +267,9 @@
- PowerShell: a parameter typed `[decimal]`, `[uint64]` or `[ulong]` keeps its function in
PowerShell, with the reasons C# gives for the same types, instead of bridging it as `f64` or
`i64`. `[uint32]`, `[double]` and `[single]` bridge as before (#1341 by @jakalijey).
+- Go: `os.ExpandEnv`, `os.TempDir`, `os.UserConfigDir`, `os.UserCacheDir` and `os.Executable`
+ count as reading the environment, as `os.Getenv` and `os.UserHomeDir` already did, in `analyze`
+ and `bridge` (#1405 by @jakalijey).
- C#: `Environment.TickCount`, `Environment.TickCount64`, `Stopwatch.GetTimestamp()`,
`Stopwatch.StartNew()` and `Stopwatch.GetElapsedTime()` count as reading the clock, also written
with `System.Diagnostics.` in full (#1399 by @jakalijey).
diff --git a/src/lang/effects.rs b/src/lang/effects.rs
index 27abc33c..a561f488 100644
--- a/src/lang/effects.rs
+++ b/src/lang/effects.rs
@@ -164,6 +164,12 @@ fn environment(lang: Lang) -> &'static [&'static str] {
"os.Getwd(",
"os.UserHomeDir(",
"os.Hostname(",
+ // `os.Expand(` stays out: it reads through the mapping function it is given.
+ "os.ExpandEnv(",
+ "os.TempDir(",
+ "os.UserConfigDir(",
+ "os.UserCacheDir(",
+ "os.Executable(",
],
Lang::Java | Lang::Kotlin => &[
"System.getenv(",
@@ -1474,6 +1480,14 @@ mod tests {
Lang::Go,
"func F(x string) string { return os.Getenv(\"HOME\") + x }",
),
+ (
+ Lang::Go,
+ "func F(x string) string { return os.ExpandEnv(\"$HOME/\" + x) }",
+ ),
+ (
+ Lang::Go,
+ "func F(x string) string { return os.TempDir() + x }",
+ ),
(
Lang::Java,
"String f(String x){ return System.getenv(\"HOME\") + x; }",