Skip to content

Commit

Permalink
fix resolve panic during type alias conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseCoretta committed Jul 3, 2023
1 parent 905958e commit 5a4592a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,18 @@ func stackTypeAliasConverter(u any) (S Stack, converted bool) {

a := typOf(u) // current (src) type
b := typOf(Stack{}) // target (dest) type
if a.ConvertibleTo(b) {
if X := valOf(u).Convert(b).Interface().(Stack); !X.IsZero() {
if s := X.String(); s != badStack && len(s) > 0 {
S = X
converted = true
return
}
}
}
if a.ConvertibleTo(b) {
X := valOf(u).Convert(b).Interface()
if assert, ok := X.(Stack); ok {
if !assert.IsZero() {
if s := assert.String(); s != badCond && len(s) > 0 {
S = assert
converted = true
return
}
}
}
}

return
}
Expand All @@ -217,11 +220,14 @@ func conditionTypeAliasConverter(u any) (C Condition, converted bool) {
a := typOf(u) // current (src) type
b := typOf(Stack{}) // target (dest) type
if a.ConvertibleTo(b) {
if X := valOf(u).Convert(b).Interface().(Condition); !X.IsZero() {
if s := X.String(); s != badCond && len(s) > 0 {
C = X
converted = true
return
X := valOf(u).Convert(b).Interface()
if assert, ok := X.(Condition); ok {
if !assert.IsZero() {
if s := assert.String(); s != badCond && len(s) > 0 {
C = assert
converted = true
return
}
}
}
}
Expand Down

0 comments on commit 5a4592a

Please sign in to comment.