Why unused global variable allowed in Go?

package main

import (
	"fmt"
)

var x int

func main() {

	var z int
}

Why x is valid and z is not valid ? isn’t it another code pollution which is strictly prohibitated in Go?

1 Like

The compiler can determine that the local private variable z is unused. The compiler can’t determine that the global private variable x is unused, only the linker can do that.

1 Like