From 61bd95bb8920b7359ff25953867ab3eb56f48666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 9 May 2022 21:06:42 +0100 Subject: [PATCH] add a test with generic code This ensures that we support obfuscating builds containing the use of type parameters, the new feature in Go 1.18. The test is small for now, but we can extend it over time. There was just one bug that kept the code from obfuscating properly; that has been fixed in https://go.dev/cl/405194, and we update x/tools to the latest master version to include it. Fixes #414. --- go.mod | 2 +- go.sum | 4 ++-- testdata/scripts/typeparams.txt | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 testdata/scripts/typeparams.txt diff --git a/go.mod b/go.mod index fed7e34..6c01c35 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/rogpeppe/go-internal v1.8.1 golang.org/x/exp v0.0.0-20220428152302-39d4317da171 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 - golang.org/x/tools v0.1.10 + golang.org/x/tools v0.1.11-0.20220509190205-b87ceec0dd4d ) require ( diff --git a/go.sum b/go.sum index 89d20fd..2e5826e 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9 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= -golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= -golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.11-0.20220509190205-b87ceec0dd4d h1:S3qBFWgWXvFR7WrB8yRhfbybHNf6ihmUn2+tewXCRrs= +golang.org/x/tools v0.1.11-0.20220509190205-b87ceec0dd4d/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/testdata/scripts/typeparams.txt b/testdata/scripts/typeparams.txt new file mode 100644 index 0000000..c64bd61 --- /dev/null +++ b/testdata/scripts/typeparams.txt @@ -0,0 +1,38 @@ +env GOGARBLE=* + +garble build +! binsubstr main$exe ${WORK} 'garble_main.go' 'GenericFunc' 'GenericVector' 'PredeclaredSignedInteger' 'StringableSignedInteger' 'CombineEmbeds' 'GenericParam' + +-- go.mod -- +module test/main + +go 1.18 + +-- garble_main.go -- +package main + +func main() { + //var _ GenericVector[int] + GenericFunc[int, int](1, 2) +} + +func GenericFunc[GenericParamA, B any](x GenericParamA, y B) {} + +type GenericVector[GenericParamT any] []GenericParamT + +type PredeclaredSignedInteger interface { + int | int8 | int16 | int32 | int64 +} + +type StringableSignedInteger interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 + + String() string +} + +type CombineEmbeds interface { + string | int + + interface { EmbeddedMethod() } + RegularMethod() +}