Skip to content

Commit c14cc8e

Browse files
authored
fix bug: enums of explicit type conversion (#1556)
Signed-off-by: sdghchj <[email protected]>
1 parent 01d20cc commit c14cc8e

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

package.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,18 @@ func (pkg *PackageDefinitions) evaluateConstValue(file *ast.File, iota int, expr
158158
if name == "uintptr" {
159159
name = "uint"
160160
}
161+
value, _ := pkg.evaluateConstValue(file, iota, arg, globalEvaluator, recursiveStack)
161162
if IsGolangPrimitiveType(name) {
162-
value, _ := pkg.evaluateConstValue(file, iota, arg, globalEvaluator, recursiveStack)
163163
value = EvaluateDataConversion(value, name)
164164
return value, nil
165165
} else if name == "len" {
166-
value, _ := pkg.evaluateConstValue(file, iota, arg, globalEvaluator, recursiveStack)
167166
return reflect.ValueOf(value).Len(), nil
168167
}
169168
typeDef := globalEvaluator.FindTypeSpec(name, file)
170169
if typeDef == nil {
171170
return nil, nil
172171
}
173-
return arg, valueExpr.Fun
172+
return value, valueExpr.Fun
174173
} else if selector, ok := valueExpr.Fun.(*ast.SelectorExpr); ok {
175174
typeDef := globalEvaluator.FindTypeSpec(fullTypeName(selector.X.(*ast.Ident).Name, selector.Sel.Name), file)
176175
if typeDef == nil {

testdata/enums/expected.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
1,
119119
2,
120120
4,
121-
8
121+
8,
122+
3
122123
],
123124
"type": "integer",
124125
"x-enum-comments": {
@@ -131,7 +132,8 @@
131132
"Mask1",
132133
"Mask2",
133134
"Mask3",
134-
"Mask4"
135+
"Mask4",
136+
"Mask5"
135137
],
136138
"name": "mask",
137139
"in": "formData"
@@ -197,7 +199,8 @@
197199
1,
198200
2,
199201
4,
200-
8
202+
8,
203+
3
201204
],
202205
"type": "integer"
203206
},
@@ -268,7 +271,8 @@
268271
1,
269272
2,
270273
4,
271-
8
274+
8,
275+
3
272276
],
273277
"x-enum-comments": {
274278
"Mask1": "Mask1",
@@ -280,7 +284,8 @@
280284
"Mask1",
281285
"Mask2",
282286
"Mask3",
283-
"Mask4"
287+
"Mask4",
288+
"Mask5"
284289
]
285290
},
286291
"types.Person": {

testdata/enums/types/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
Mask2 /* Mask2 */
3131
Mask3 // Mask3
3232
Mask4 // Mask4
33+
Mask5 = Mask(A + B)
3334
)
3435

3536
type Type string

0 commit comments

Comments
 (0)