Skip to content

noinit doesn't know about nil slices #82

@kluzzebass

Description

@kluzzebass

I tried to use noinit with a []byte slice, but the parser complained that field must be a pointer to have noinit. It seems a bit unnecessary to insist on having a pointer to a slice, since a slice in itself can be nil. Consider the following code:

package main

import "fmt"

type Lala struct {
	Blah []byte
}

func main() {
	lala := Lala{}
	if lala.Blah == nil {
		fmt.Println("Blah is nil")
	}
	lala.Blah = []byte{}
	if lala.Blah != nil {
		fmt.Println("Blah is not nil")
	}
}

The result is:

Blah is nil
Blah is not nil

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions