Skip to content

cmd/compile: confusing error message for non-bool comparison #41500

@smasher164

Description

@smasher164

What version of Go are you using (go version)?

go version go1.15.2 darwin/amd64

What did you do?

I tried to compile the following program: https://play.golang.org/p/k1xIda2_lTk

package main

type Struct struct {
	Slice []int
}

func main() {
	var x *Struct
	if x == nil || len(x.Slice) {
	}
}

I forgot to add len(x.Slice) == 0.

What did you expect to see?

non-bool len(x.Slice) (type int) used as if condition

What did you see instead?

cannot use x == nil (type untyped bool) as type int

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions