8000 Load input failed: unknown package error with aliased imports · Issue #254 · uber-go/mock · GitHub
[go: up one dir, main page]

Skip to content

Load input failed: unknown package error with aliased imports #254

Open

Description

@jDomantas

Actual behavior

File contents:

// file subpkg/alphabetically_first.go
package subpkg

import (
	"time"
)

var _ time.Time


// file subpkg/alphabetically_second.go
package subpkg

import (
	aliased_time_import "time"
)

type I1 interface {
	Foo(t aliased_time_import.Time)
}


// file x.go
package mockgen_repro

import "mockgen_repro/subpkg"

type I2 interface {
	subpkg.I1
}


// file go.mod
module mockgen_repro

go 1.24.0

Mockgen in source mode on x.go fails:

# mockgen -source x.go
2025/05/20 11:53:46 Loading input failed: .../mockgen_repro/subpkg/alphabetically_second.go:8:5: failed parsing arguments: .../mockgen_repro/subpkg/alphabetically_second.go:8:8: unknown package "aliased_time_import"

Expected behavior

Mock generation should succeed (like it does if I rename alphabetically_first.go and alphabetically_second.go to be ordered the other way around).

Additional Information

  • gomock mode (reflect or source): source
  • gomock version or git ref: v0.5.2
  • golang version: 1.24.0

Triage Notes for the Maintainers

There is some existing discussion about this bug in #166, but the original reported bug there was different and the issue got closed, so I'm reporting it here again with the reproduction specifically for the issue that I encountered.

Activity

  1. hdimer commented on Jul 30, 2026

    @hdimer

    Root cause: in source mode, parsePackage reads the imported package's imports from ast.MergePackageFiles(..., FilterImportDuplicates). That filter dedupes imports by path, so when one file imports a package plainly and another aliases it, the alias gets dropped and referencing it later fails with unknown package. Reading imports per-file instead of from the merged file keeps the alias. Opened #311 with the fix and a regression test.

  2. dragonsinth commented on Oct 15, 2026

    @dragonsinth

    This is a big issue when generating mocks for protos and the new grpc plugin:

    x.pb.go:

    	_ "google.golang.org/protobuf/types/known/emptypb"

    x_grpc.pb.go:

    	emptypb "google.golang.org/protobuf/types/known/emptypb"
    

    mockgen now breaks reading this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      0