Skip to content

Bug: v66.0.0 causes "cannot use *github.Commit as github.Commit" compiler error #3702

@scopweb

Description

@scopweb

Description

When using version v66.0.0 of go-github, the Go compiler throws a contradictory error when initializing a github.RepositoryContentResponse struct with a literal for the Commit field. The error message suggests a type mismatch (cannot use *github.Commit as github.Commit), even though the struct definition for RepositoryContentResponse clearly defines the Commit field as a pointer (*github.Commit).

This issue does not occur in version v65.0.0, which compiles correctly with the exact same code. This suggests a potential regression or a subtle breaking change in the type definitions of v66.0.0.

Environment

  • Go Version: go version go1.23.0
  • go-github Version: v66.0.0

Steps to Reproduce

  1. Create a new Go project.

  2. Add the go-github v66 dependency:

    go get github.com/google/go-github/[email protected]
  3. Create a test file (e.g., main_test.go) with the following minimal reproducible code:

    package main_test
    
    import (
        "testing"
        "github.com/google/go-github/v66/github"
    )
    
    func TestRepositoryContentResponseInitialization(t *testing.T) {
        // This code fails to compile with go-github v66.0.0
        _ = &github.RepositoryContentResponse{
            Commit: &github.Commit{SHA: github.String("12345")},
        }
    }
  4. Try to build or test the project:

    go test

Expected Behavior

The code should compile successfully, as the Commit field of github.RepositoryContentResponse is a pointer (*github.Commit), and we are providing a pointer to a github.Commit literal.

Actual Behavior

The compiler returns the following error:

project/path
./main_test.go:11:3: cannot use &github.Commit{…} (value of type *github.Commit) as github.Commit value in struct literal

Workaround

Downgrading the library to v65.0.0 resolves the issue completely.

go get github.com/google/go-github/[email protected]

With v65, the same code compiles without any errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions