[pkgsite] internal/breakings/syntax/types: Array.Same

1 view
Skip to first unread message

Jonathan Amsterdam (Gerrit)

unread,
12:44 PM (10 hours ago) 12:44 PM
to Hyang-Ah Hana Kim, Ethan Lee, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee and Hyang-Ah Hana Kim

Jonathan Amsterdam has uploaded the change for review

Jonathan Amsterdam would like Hyang-Ah Hana Kim and Ethan Lee to review this change.

Commit message

internal/breakings/syntax/types: Array.Same

Add Same method for ArrayType.

For golang/go#80385.

TAG=agy
CONV=62739b83-d7f7-4685-a929-0177ae5cd32b
Change-Id: I231e04b8cfa8c5b3963075970bc12eedda283749

Change diff

diff --git a/internal/breakings/syntax/types/same_test.go b/internal/breakings/syntax/types/same_test.go
index a07cd20..0c4afda 100644
--- a/internal/breakings/syntax/types/same_test.go
+++ b/internal/breakings/syntax/types/same_test.go
@@ -76,3 +76,28 @@
})
}
}
+
+func TestArrayTypeSame(t *testing.T) {
+ tests := []struct {
+ name string
+ a1 *ArrayType
+ t2 Type
+ want tri.Bool
+ }{
+ {"both slice same elt", &ArrayType{Elt: tInt}, &ArrayType{Elt: tInt}, tri.Yes},
+ {"both slice diff elt", &ArrayType{Elt: tInt}, &ArrayType{Elt: tString}, tri.No},
+ {"slice vs array", &ArrayType{Elt: tInt}, &ArrayType{Len: "10", Elt: tInt}, tri.No},
+ {"both array same len same elt", &ArrayType{Len: "10", Elt: tInt}, &ArrayType{Len: "10", Elt: tInt}, tri.Yes},
+ {"both array diff len", &ArrayType{Len: "10", Elt: tInt}, &ArrayType{Len: "2*5", Elt: tInt}, tri.Maybe},
+ {"vs imported named", &ArrayType{Elt: tInt}, tImpA, tri.Maybe},
+ {"vs bad type", &ArrayType{Elt: tInt}, tBad, tri.Maybe},
+ {"vs local named", &ArrayType{Elt: tInt}, tInt, tri.No},
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := tc.a1.Same(tc.t2); got != tc.want {
+ t.Errorf("%s.Same(%s) = %v, want %v", tc.a1, tc.t2, got, tc.want)
+ }
+ })
+ }
+}
diff --git a/internal/breakings/syntax/types/types.go b/internal/breakings/syntax/types/types.go
index f70a417..ad1b597 100644
--- a/internal/breakings/syntax/types/types.go
+++ b/internal/breakings/syntax/types/types.go
@@ -121,7 +121,23 @@
return fmt.Sprintf("[%s]%s", t.Len, t.Elt.String())
}

-func (*ArrayType) Same(Type) tri.Bool { panic("unimplemented") }
+func (a1 *ArrayType) Same(t Type) tri.Bool {
+ if a2, ok := t.(*ArrayType); ok {
+ if (a1.Len == "") != (a2.Len == "") {
+ // slice vs. array
+ return tri.No
+ }
+ if a1.Len != a2.Len {
+ // maybe one is a literal and the other is a const.
+ return tri.Maybe
+ }
+ return a1.Elt.Same(a2.Elt)
+ }
+ if badOrPossibleAlias(t) {
+ return tri.Maybe
+ }
+ return tri.No
+}

// MapType is the syntax for a map type.
type MapType struct {

Change information

Files:
  • M internal/breakings/syntax/types/same_test.go
  • M internal/breakings/syntax/types/types.go
Change size: S
Delta: 2 files changed, 42 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
  • Hyang-Ah Hana Kim
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I231e04b8cfa8c5b3963075970bc12eedda283749
Gerrit-Change-Number: 811940
Gerrit-PatchSet: 1
Gerrit-Owner: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Attention: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

kokoro (Gerrit)

unread,
1:17 PM (9 hours ago) 1:17 PM
to Jonathan Amsterdam, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Ethan Lee, Hyang-Ah Hana Kim, golang-co...@googlegroups.com
Attention needed from Ethan Lee, Hyang-Ah Hana Kim and Jonathan Amsterdam

kokoro voted kokoro-CI+1

Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/2ccc0491-4dcd-47f8-983d-dac150e7b452

kokoro-CI+1
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
  • Hyang-Ah Hana Kim
  • Jonathan Amsterdam
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    • requirement satisfiedkokoro-CI-Passes
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pkgsite
    Gerrit-Branch: master
    Gerrit-Change-Id: I231e04b8cfa8c5b3963075970bc12eedda283749
    Gerrit-Change-Number: 811940
    Gerrit-PatchSet: 1
    Gerrit-Owner: Jonathan Amsterdam <j...@google.com>
    Gerrit-Reviewer: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
    Gerrit-Attention: Ethan Lee <etha...@google.com>
    Gerrit-Comment-Date: Fri, 07 Aug 2026 17:17:11 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages