Skip to content

Commit

Permalink
go/types, types2: add a test case to ConvertibleTo
Browse files Browse the repository at this point in the history
string(int) conversions are somewhat special and deserve an entry.

Change-Id: Ia68d047cfdb2f98e837bf663659f7f46404b16ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/355989
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
griesemer committed Oct 14, 2021
1 parent 440b63b commit 0400d53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/api_test.go
Expand Up @@ -1655,15 +1655,15 @@ func TestConvertibleTo(t *testing.T) {
}{
{Typ[Int], Typ[Int], true},
{Typ[Int], Typ[Float32], true},
{Typ[Int], Typ[String], true},
{newDefined(Typ[Int]), Typ[Int], true},
{newDefined(new(Struct)), new(Struct), true},
{newDefined(Typ[Int]), new(Struct), false},
{Typ[UntypedInt], Typ[Int], true},
{NewSlice(Typ[Int]), NewPointer(NewArray(Typ[Int], 10)), true},
{NewSlice(Typ[Int]), NewArray(Typ[Int], 10), false},
{NewSlice(Typ[Int]), NewPointer(NewArray(Typ[Uint], 10)), false},
// Untyped string values are not permitted by the spec, so the below
// behavior is undefined.
// Untyped string values are not permitted by the spec, so the behavior below is undefined.
{Typ[UntypedString], Typ[String], true},
} {
if got := ConvertibleTo(test.v, test.t); got != test.want {
Expand Down
4 changes: 2 additions & 2 deletions src/go/types/api_test.go
Expand Up @@ -1631,15 +1631,15 @@ func TestConvertibleTo(t *testing.T) {
}{
{Typ[Int], Typ[Int], true},
{Typ[Int], Typ[Float32], true},
{Typ[Int], Typ[String], true},
{newDefined(Typ[Int]), Typ[Int], true},
{newDefined(new(Struct)), new(Struct), true},
{newDefined(Typ[Int]), new(Struct), false},
{Typ[UntypedInt], Typ[Int], true},
{NewSlice(Typ[Int]), NewPointer(NewArray(Typ[Int], 10)), true},
{NewSlice(Typ[Int]), NewArray(Typ[Int], 10), false},
{NewSlice(Typ[Int]), NewPointer(NewArray(Typ[Uint], 10)), false},
// Untyped string values are not permitted by the spec, so the below
// behavior is undefined.
// Untyped string values are not permitted by the spec, so the behavior below is undefined.
{Typ[UntypedString], Typ[String], true},
} {
if got := ConvertibleTo(test.v, test.t); got != test.want {
Expand Down

0 comments on commit 0400d53

Please sign in to comment.