Skip to content

impossible-platform-comparison

Detect GOOS and GOARCH comparisons excluded by build constraints.

Updated View as Markdown

Default severity: warning

A file’s build constraints limit the operating systems and architectures on which its code can run. Comparing runtime.GOOS or runtime.GOARCH with an excluded known target has a fixed result.

Platform aliases are respected: Android satisfies the linux tag, iOS satisfies darwin, and Illumos satisfies solaris.

Bad

//go:build linux

if runtime.GOOS == "windows" { // reported
    unreachable()
}

Good

//go:build linux

if runtime.GOOS == "linux" {
	useLinuxPath()
}
Navigation

Type to search…

↑↓ navigate↵ selectEsc close