Skip to content

Commit a3c3302

Browse files
authored
Support aliased types in overrides (#28)
1 parent 8effaad commit a3c3302

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

internal/tests/alias/input.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by the MIT license,
33
// which can be found in the LICENSE file.
44

5-
//go:generate go run github.com/fjl/gencodec -type X -out output.go
5+
//go:generate go run github.com/fjl/gencodec -type X -field-override xOverride -out output.go
66

77
package alias
88

@@ -19,10 +19,20 @@ type (
1919
// Demonstrate recursive unaliasing
2020
intermediate = big.Int
2121
AliasedTwice = intermediate
22+
23+
Element struct{}
24+
ElementDeriv Element
25+
Slice []Element
26+
SliceAlias = Slice
2227
)
2328

2429
type X struct {
2530
A Aliased
2631
B AliasedTwice
2732
C other.Int
33+
D SliceAlias
34+
}
35+
36+
type xOverride struct {
37+
D []ElementDeriv
2838
}

internal/tests/alias/output.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types_util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func underlying[T types.Type](typ types.Type) T {
101101
switch t := typ.(type) {
102102
case *types.Named:
103103
typ = t.Underlying()
104+
case *types.Alias:
105+
typ = t.Rhs()
104106
case T:
105107
return t
106108
default:

0 commit comments

Comments
 (0)