Skip to content

Commit 0d4bde0

Browse files
committed
Fix alias clobbering to enum
1 parent de3414d commit 0d4bde0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/visitors/enum.visitor.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package visitors
22

33
import (
4-
"fmt"
54
"go/ast"
65
"go/types"
76

@@ -173,10 +172,6 @@ func (v *EnumVisitor) getEnumValueDefinitions(
173172
continue
174173
}
175174

176-
if enumTypeName.Name() != constObj.Name() {
177-
fmt.Println("")
178-
}
179-
180175
// To avoid clobbering consts that happen to have the same type under aliases/enums,
181176
// we check the actual underlying type name as well.
182177
if curObjAlias, isCurObjAlias := constObj.Type().(*types.Alias); isCurObjAlias {

gast/ast.utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,15 @@ func IsEnumLike(pkg *packages.Package, spec *ast.TypeSpec) bool {
640640
if !ok {
641641
continue
642642
}
643+
644+
// To avoid clobbering consts that happen to have the same type under aliases/enums,
645+
// we check the actual underlying type name as well.
646+
if curObjAlias, isCurObjAlias := constVal.Type().(*types.Alias); isCurObjAlias {
647+
if typeName.Name() != curObjAlias.Obj().Name() {
648+
continue
649+
}
650+
}
651+
643652
if types.Identical(constVal.Type(), typeName.Type()) {
644653
return true
645654
}

0 commit comments

Comments
 (0)