No warning on mismatching types
Answered
I have two types in my codebase, each in a different package. Defined as:
package comEvent
type Type int16
// Type Constants
const UserClick Type = 1
// ... more constants below
and
package comState
type Type string
// Type Constants
const ConfirmedByUser Type = "confirmed-awaiting-approval"
// ... more constants below
And I have a few functions which use these `Type` types from these packages to enforce that only valid/acceptable values in the code can be used. However, GoLand won't show me an error in the editor when using one of the types (say comEvent.Type) at place where another (say comState.Type) is expected!
For example:
// function defined as:
func UpdateState(uId int64, newState comState.Type) {
// ... code here
}
//--------------------
// This call does not show me a warning in Editor:
UpdateState(int64(123), comEvent.UserClick)
Only when I compile, the go compiler tells me the problem. Why can't Goland tell me beforehand?
Interestingly (and I hope it helps in debugging the issue): If I rename the `Type`s to something else (e.g. `Typ`, `EventType` etc.) starts showing the error!
Please sign in to leave a comment.
Thanks for the bug report.
It is a known issue. Feel free to follow GO-10206.