Skip to content

Commit

Permalink
fix: Work around Go bug 68877 until Go 1.23.1 is released (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Aug 23, 2024
1 parent 7862d53 commit 156f83c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
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

0 comments on commit 156f83c

Please sign in to comment.