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

Upgrade the Go version to v1.18, and x/tools to v0.1.11. Support generics better. #325

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Upgrade the Go version to v1.18, and x/tools to v0.1.11.
Address the differences related to the new SSA format.
Remove errors/warnings on generics types, and add unit tests.
guodongli-google committed May 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4bccb4ff3612fecd585b1a48de5e2997315c1e1f
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ on:
branches: [master]

env:
GO_VERSION: "1.14"
GO_VERSION: "1.18"

jobs:
lint:
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ go 1.18

require (
github.com/google/go-cmp v0.5.2
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171
golang.org/x/tools v0.1.11-0.20220504225841-45c8a7131235
sigs.k8s.io/yaml v1.2.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171 h1:DZhP7zSquENyG3Yb6ZpGqNEtgE8dfXhcLcheIF9RQHY=
golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
3 changes: 2 additions & 1 deletion internal/pkg/sourceinfer/analyzer.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ import (
"github.com/google/go-flow-levee/internal/pkg/config"
"github.com/google/go-flow-levee/internal/pkg/fieldtags"
"github.com/google/go-flow-levee/internal/pkg/utils"
"golang.org/x/exp/typeparams"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
@@ -163,7 +164,7 @@ func findObjects(t types.Type) map[types.Object]bool {
// these do not contain relevant objects
case *types.Pointer:
// this should be unreachable due to the dereference above
case *types.TypeParam, *types.Union:
case *typeparams.TypeParam, *typeparams.Union:
// generics are not resolved yet
default:
// The above should be exhaustive. Reaching this default case is an error.
3 changes: 2 additions & 1 deletion internal/pkg/sourcetype/sourcetype.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ package sourcetype
import (
"fmt"
"go/types"
"golang.org/x/exp/typeparams"

"github.com/google/go-flow-levee/internal/pkg/config"
"github.com/google/go-flow-levee/internal/pkg/fieldtags"
@@ -66,7 +67,7 @@ func isSourceType(c *config.Config, tf fieldtags.ResultType, t types.Type, seen
case *types.Basic, *types.Tuple, *types.Interface, *types.Signature:
// These types do not currently represent possible source types
return false
case *types.TypeParam, *types.Union:
case *typeparams.TypeParam, *typeparams.Union:
// Generics are not resolved yet
return false
default:
14 changes: 14 additions & 0 deletions internal/pkg/sourcetype/testdata/test_generics.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package test

type G[T any] struct{}