Skip to content

false negative in defer assignment #93

@mrwonko

Description

@mrwonko

This code intends to overwrite a function's return value, but ineffectually assigns to a local variable instead:

package main

import (
	"errors"
	"fmt"
)

func main() {
	fmt.Println("Hello", ineffassignTest()) // Hello <nil>
}

func ineffassignTest() error {
	var err error
	defer func() {
		err = errors.New("ineffectual assignment")
	}()
	return err // always returns 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