Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Panic on array parsing if length is externally defined #561

Closed
jmaeso opened this issue May 20, 2021 · 1 comment · Fixed by #569
Closed

Panic on array parsing if length is externally defined #561

jmaeso opened this issue May 20, 2021 · 1 comment · Fixed by #569

Comments

@jmaeso
Copy link

jmaeso commented May 20, 2021

Actual behavior

generating code for the following interface makes the tool to panic.

(Note: math constant used just for convenience. Can be any other package-defined constant, not a hardcoded value)

type Fooer interface {
    Foo([math.MaxInt8]string)
}

Output: panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.BasicLit

Expected behavior

Generate a mocked struct with a method that takes a [127]string{} (or [math.MaxInt8]string{}) array

To Reproduce Steps to reproduce the behavior
Explained in the "Actual behaviour" section

Additional Information

  • gomock mode (reflect or source): source
  • gomock version or git ref: v1.5.0
  • golang version: go version go1.15.8 darwin/amd64

Triage Notes for the Maintainers

@codyoss
Copy link
Member

codyoss commented Jun 3, 2021

Thanks for the report. It looks like more work needs to be done onto the changes that were made in #520. I think those changes assume that the const is defined locally. I would be willing to accept a PR for this issue.

@codyoss codyoss added this to the v1.6.0 milestone Jun 10, 2021
codyoss pushed a commit that referenced this issue Jun 11, 2021
Fixes #561 - Panic on array parsing if length is externally defined

It also fixes the following minor problems in TestParseArrayWithConstLength, a test function related to this feature.

It doesn't check all outputs to be asserted.
It doesn't initialize some of the fields in mockgen.fileParser, even though they are initialized in the production code. (Actually, it caused an unnecessary test error by test data I added)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants