Skip to content

Commit

Permalink
fixed an issue with interfaces not being comparable in go 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
e-nikolov committed Apr 6, 2022
1 parent 28a8ba2 commit 47477ed
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions openapi2/funcinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ func fixFuncLine(line int, fset *token.FileSet, astFile *ast.File) int {

var stack []ast.Node
ast.Inspect(astFile, func(n ast.Node) bool {
stack = updateNodeStack(stack, n)
if n != nil {
stack = append(stack, n)
} else {
stack = stack[:len(stack)-1]
}

// Check if the current node is on the specified line.
if n == nil || fset.Position(n.Pos()).Line != line {
Expand All @@ -150,17 +154,3 @@ func fixFuncLine(line int, fset *token.FileSet, astFile *ast.File) int {

return fixedFuncLine
}

func updateNodeStack[T comparable](stack []T, n T) []T {
var nilT T

if n == nilT {
// pop on nil
stack = stack[:len(stack)-1]
} else {
// push
stack = append(stack, n)
}

return stack
}

0 comments on commit 47477ed

Please sign in to comment.