-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
Go 1.23 changed how go/types handles type aliases, which breaks code generation if you use a package that has an alias type (example: https://pkg.go.dev/github.com/golang/[email protected]/ptypes/timestamp#Timestamp ). These were getting generated as just the unqualified name, without the package. If you used a previous version of Go, it meant that if that aliased type was in an internal package we'd try to import the internal package instead, resulting in a compilation error. Add a switch to handle that case, and bump the go.mod version to support using types.Alias.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/matryer/moq | ||
|
||
go 1.22.5 | ||
go 1.23 | ||
|
||
require ( | ||
github.com/pmezard/go-difflib v1.0.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package typealias | ||
|
||
import ( | ||
"github.com/matryer/moq/pkg/moq/testpackages/typealiastwo" | ||
) | ||
|
||
type Example interface { | ||
Check failure on line 7 in pkg/moq/testpackages/typealias/typealias.go GitHub Actions / test (ubuntu-latest, oldstable)
Check failure on line 7 in pkg/moq/testpackages/typealias/typealias.go GitHub Actions / test (ubuntu-latest, stable)
Check failure on line 7 in pkg/moq/testpackages/typealias/typealias.go GitHub Actions / test (ubuntu-latest, oldstable)
|
||
Do(a typealiastwo.AliasType, b typealiastwo.GenericAliasType) error | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package typealiasinternal | ||
|
||
// we shouldn't be able to import these types directly, you need to use the alias in the parent package | ||
Check failure on line 3 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, oldstable)
Check failure on line 3 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, stable)
Check failure on line 3 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, oldstable)
Check failure on line 3 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, stable)
|
||
type MyInternalType struct { | ||
Foo int | ||
} | ||
|
||
type MyGenericType[T any] struct { | ||
Check failure on line 8 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, oldstable)
Check failure on line 8 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, stable)
Check failure on line 8 in pkg/moq/testpackages/typealiastwo/internal/typealiasinternal/typealiasinternal.go GitHub Actions / test (ubuntu-latest, oldstable)
|
||
A T | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package typealiastwo | ||
|
||
import "github.com/matryer/moq/pkg/moq/testpackages/typealiastwo/internal/typealiasinternal" | ||
|
||
type AliasType = typealiasinternal.MyInternalType | ||
Check failure on line 5 in pkg/moq/testpackages/typealiastwo/typealiastwo.go GitHub Actions / test (ubuntu-latest, oldstable)
Check failure on line 5 in pkg/moq/testpackages/typealiastwo/typealiastwo.go GitHub Actions / test (ubuntu-latest, stable)
Check failure on line 5 in pkg/moq/testpackages/typealiastwo/typealiastwo.go GitHub Actions / test (ubuntu-latest, oldstable)
|
||
|
||
type GenericAliasType = typealiasinternal.MyGenericType[int] | ||
Check failure on line 7 in pkg/moq/testpackages/typealiastwo/typealiastwo.go GitHub Actions / test (ubuntu-latest, oldstable)
Check failure on line 7 in pkg/moq/testpackages/typealiastwo/typealiastwo.go GitHub Actions / test (ubuntu-latest, stable)
Check failure on line 7 in pkg/moq/testpackages/typealiastwo/typealiastwo.go GitHub Actions / test (ubuntu-latest, oldstable)
|