Skip to content

Mock method parameter shadows unexported types #216

@bitflipp

Description

@bitflipp

Please consider the following snippet:

package main

type s struct{}

//go:generate moq -out i_test.go . i
type i interface {
	m(s s)
}

moq generates:

// m calls mFunc.
func (mock *iMock) m(s s) {            // Type s is shadowed.
	if mock.mFunc == nil {
		panic("iMock.mFunc: method is nil but i.m was just called")
	}
	callInfo := struct {
		S s                    // Compiler error: s (variable of type s) is not a type.
	}{
		S: s,
	}
	mock.lockm.Lock()
	mock.calls.m = append(mock.calls.m, callInfo)
	mock.lockm.Unlock()
	mock.mFunc(s)
}

This may (and arguably should) be remedied by changing the interface method to m(somethingDescriptive s), yet it's an invalid output generated from a valid input.

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