Skip to content

Commit c4b87c2

Browse files
authored
fix: gob encoder panic if used in alias types. (#4)
Context: golang/go#36345
2 parents a2b4473 + 687d94f commit c4b87c2

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

hcldec/gob.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ func init() {
1212
// specs can be sent over gob channels, such as using
1313
// github.com/hashicorp/go-plugin with plugins that need to describe
1414
// what shape of configuration they are expecting.
15-
gob.Register(ObjectSpec(nil))
16-
gob.Register(TupleSpec(nil))
17-
gob.Register((*AttrSpec)(nil))
18-
gob.Register((*LiteralSpec)(nil))
19-
gob.Register((*ExprSpec)(nil))
20-
gob.Register((*BlockSpec)(nil))
21-
gob.Register((*BlockListSpec)(nil))
22-
gob.Register((*BlockSetSpec)(nil))
23-
gob.Register((*BlockMapSpec)(nil))
24-
gob.Register((*BlockLabelSpec)(nil))
25-
gob.Register((*DefaultSpec)(nil))
15+
// NOTE(i4k): use RegisterName() instead of Register() because the latter panics
16+
// if the registered types are used in alias types.
17+
gob.RegisterName("hcldec.ObjectSpec", ObjectSpec(nil))
18+
gob.RegisterName("hcldec.TupleSpec", TupleSpec(nil))
19+
gob.RegisterName("*hcldec.AttrSpec", (*AttrSpec)(nil))
20+
gob.RegisterName("*hcldec.LiteralSpec", (*LiteralSpec)(nil))
21+
gob.RegisterName("*hcldec.ExprSpec", (*ExprSpec)(nil))
22+
gob.RegisterName("*hcldec.BlockSpec", (*BlockSpec)(nil))
23+
gob.RegisterName("*hcldec.BlockListSpec", (*BlockListSpec)(nil))
24+
gob.RegisterName("*hcldec.BlockSetSpec", (*BlockSetSpec)(nil))
25+
gob.RegisterName("*hcldec.BlockMapSpec", (*BlockMapSpec)(nil))
26+
gob.RegisterName("*hcldec.BlockLabelSpec", (*BlockLabelSpec)(nil))
27+
gob.RegisterName("*hcldec.DefaultSpec", (*DefaultSpec)(nil))
2628
}

0 commit comments

Comments
 (0)