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

fix: Work around Go bug 68877 until Go 1.23.1 is released #121

Merged
merged 2 commits into from
Aug 23, 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
7 changes: 7 additions & 0 deletions internal/index/scip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"fmt"
"go/ast"
"os"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -87,6 +88,12 @@ func ListMissing(opts config.IndexOpts) (missing []string, err error) {
}

func Index(writer func(proto.Message), opts config.IndexOpts) error {
if os.Getenv("GODEBUG") == "" {
// TODO: Remove this after upgrading to Go 1.23.1
// See https://github.com/golang/go/issues/68894
os.Setenv("GODEBUG", "gotypesalias=0")
}

// Emit Metadata.
// NOTE: Must be the first field emitted
writer(&scip.Metadata{
Expand Down
9 changes: 9 additions & 0 deletions internal/testdata/snapshots/input/alias/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

// Check that we don't panic
// Copied from https://github.com/golang/go/issues/68877#issuecomment-2290000187
type (
T struct{}
U = T
S U
)
51 changes: 51 additions & 0 deletions internal/testdata/snapshots/output/alias/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main
// ^^^^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/
// documentation
// > package main

// Check that we don't panic
// Copied from https://github.com/golang/go/issues/68877#issuecomment-2290000187
type (
T struct{}
// ^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/T#
// documentation
// > ```go
// > type T struct
// > ```
// documentation
// > Check that we don't panic
// > Copied from https://github.com/golang/go/issues/68877#issuecomment-2290000187
// documentation
// > ```go
// > struct{}
// > ```
U = T
// ^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/U#
// documentation
// > ```go
// > type U = T
// > ```
// documentation
// > Check that we don't panic
// > Copied from https://github.com/golang/go/issues/68877#issuecomment-2290000187
// documentation
// > ```go
// > struct{}
// > ```
// ^ reference github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/T#
S U
// ^ definition github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/S#
// documentation
// > ```go
// > type S struct
// > ```
// documentation
// > Check that we don't panic
// > Copied from https://github.com/golang/go/issues/68877#issuecomment-2290000187
// documentation
// > ```go
// > struct{}
// > ```
// ^ reference github.com/sourcegraph/scip-go . `github.com/sourcegraph/scip-go/internal/testdata/snapshots/input/alias`/U#
)

2 changes: 1 addition & 1 deletion internal/testdata/snapshots/output/testdata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
// ^^^^^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/TestEqualsStruct#
// documentation
// > ```go
// > type TestEqualsStruct struct
// > type TestEqualsStruct = struct
// > ```
// documentation
// > ```go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
// > ```go
// > func (T1).F1()
// > ```
// relationship 0.1.test `sg/testdata`/I1#F1. implementation
// relationship 0.1.test `sg/testdata`/I1#F1. implementation
// relationship 0.1.test `sg/testdata`/I1#F1. implementation

type T2 int
Expand Down Expand Up @@ -104,13 +106,15 @@
// > ```go
// > int
// > ```
// relationship 0.1.test `sg/testdata`/I1# implementation
// ^^ reference 0.1.test `sg/testdata`/T1#
type A12 = A1
// ^^^ definition 0.1.test `sg/testdata`/A12#
// documentation
// > ```go
// > int
// > ```
// relationship 0.1.test `sg/testdata`/I1# implementation
// ^^ reference 0.1.test `sg/testdata`/A1#

type InterfaceWithNonExportedMethod interface {
Expand Down
4 changes: 2 additions & 2 deletions internal/testdata/snapshots/output/testdata/typealias.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// ^^^^^^^^^^^^ definition 0.1.test `sg/testdata`/SecretBurger#
// documentation
// > ```go
// > type SecretBurger struct
// > type SecretBurger = secret.Burger
// > ```
// documentation
// > Type aliased doc
Expand All @@ -28,7 +28,7 @@
// ^^^^^^^^^ definition 0.1.test `sg/testdata`/BadBurger#
// documentation
// > ```go
// > type BadBurger struct
// > type BadBurger = struct
// > ```
// documentation
// > ```go
Expand Down
Loading