r/golang • u/bdu-komrad • 8h ago
help IDE says Variable declared above and used in if statement is not used
This must be a scoping issue, but I can't figure it out or find the answer from google or AI.
My IDE says that "videoFileExists" is declared but not used. But I'm using it inside of the if statement, and the IDE does not show an error at " videoFileExists = true" .
In my mind, of the declared variable wasn't used, then " videoFileExists = true" should show an errors since the variable I'm assigning to has not been declare.
I'm confused. Copilot fusion has no clue either. It wants to delete "var videoFileExists..."
for _, infoJsonFile := range infoJsonFiles {
var (
videoFileExists, videoThumbnailFileExists, videoNfoFileExists bool
)
// calculate matching video file basename
videoFilePath := strings.Replace(infoJsonFile, ".info.json", ".mkv")
// check if video file exists
if slices.Contains(videoFiles, videoFilePath) {
videoFileExists = true
}