r/golang • • 8h ago

help IDE says Variable declared above and used in if statement is not used

2 Upvotes

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
        }

r/golang • • 15h ago

show & tell Go Scheduler: Goroutines Under the Hood

Thumbnail
youtu.be
25 Upvotes

r/golang • • 19h ago

Go proposal tracker

Thumbnail
antonz.org
54 Upvotes

If you are curious about what is coming in the following releases of Go, this is a very nice way to see where the language is leaning. You can see there things like sync.Counter, composite literals without types, or maps.Grow.