Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Go 1.18 #21

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions astequal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package astequal
import (
"go/ast"
"go/token"

"golang.org/x/exp/typeparams"
)

// Node reports whether two AST nodes are structurally (deep) equal.
Expand Down Expand Up @@ -109,8 +107,8 @@ func astExprEq(x, y ast.Expr) bool {
y, ok := y.(*ast.IndexExpr)
return ok && astIndexExprEq(x, y)

case *typeparams.IndexListExpr:
y, ok := y.(*typeparams.IndexListExpr)
case *ast.IndexListExpr:
y, ok := y.(*ast.IndexListExpr)
return ok && astIndexListExprEq(x, y)

case *ast.SliceExpr:
Expand Down Expand Up @@ -323,7 +321,7 @@ func astFuncTypeEq(x, y *ast.FuncType) bool {
}
return astFieldListEq(x.Params, y.Params) &&
astFieldListEq(x.Results, y.Results) &&
astFieldListEq(typeparams.ForFuncType(x), typeparams.ForFuncType(y))
astFieldListEq(forFuncType(x), forFuncType(y))
}

func astBasicLitEq(x, y *ast.BasicLit) bool {
Expand Down Expand Up @@ -378,7 +376,7 @@ func astIndexExprEq(x, y *ast.IndexExpr) bool {
return astExprEq(x.X, y.X) && astExprEq(x.Index, y.Index)
}

func astIndexListExprEq(x, y *typeparams.IndexListExpr) bool {
func astIndexListExprEq(x, y *ast.IndexListExpr) bool {
if x == nil || y == nil {
return x == y
}
Expand Down Expand Up @@ -690,7 +688,7 @@ func astTypeSpecEq(x, y *ast.TypeSpec) bool {
return x == y
}
return astIdentEq(x.Name, y.Name) && astExprEq(x.Type, y.Type) &&
astFieldListEq(typeparams.ForTypeSpec(x), typeparams.ForTypeSpec(y))
astFieldListEq(forTypeSpec(x), forTypeSpec(y))
}

func astValueSpecEq(x, y *ast.ValueSpec) bool {
Expand Down Expand Up @@ -755,3 +753,19 @@ func astExprSliceEq(xs, ys []ast.Expr) bool {
}
return true
}

// forTypeSpec returns n.TypeParams.
func forTypeSpec(n *ast.TypeSpec) *ast.FieldList {
if n == nil {
return nil
}
return n.TypeParams
}

// forFuncType returns n.TypeParams.
func forFuncType(n *ast.FuncType) *ast.FieldList {
if n == nil {
return nil
}
return n.TypeParams
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/go-toolsmith/astequal

go 1.16
go 1.18

require (
github.com/go-toolsmith/strparse v1.1.0
github.com/google/go-cmp v0.6.0
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ github.com/go-toolsmith/strparse v1.1.0/go.mod h1:7ksGy58fsaQkGQlY8WVoBFNyEPMGuJ
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9 h1:6WHiuFL9FNjg8RljAaT7FNUuKDbvMqS1i5cr2OE2sLQ=
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=