Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not depend on undefined assignment order #5

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 46 additions & 23 deletions wit/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ func (c *worldItemCodec) DecodeField(dec codec.Decoder, name string) error {
switch name {
case "interface":
var v *Interface
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
case "function":
var v *Function
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
case "type":
var v *TypeDef
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
}
return err
}
Expand Down Expand Up @@ -248,10 +251,12 @@ func (c *typeOwnerCodec) DecodeField(dec codec.Decoder, name string) error {
switch name {
case "interface":
var v *Interface
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
case "world":
var v *World
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
}
return err
}
Expand All @@ -274,43 +279,56 @@ func (c *typeDefKindCodec) DecodeField(dec codec.Decoder, name string) error {
switch name {
case "record":
v := &Record{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "resource": // TODO: this might not be necessary
v := &Resource{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "handle":
var v Handle
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
case "flags":
v := &Flags{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "tuple":
v := &Tuple{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "variant":
v := &Variant{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "enum":
v := &Enum{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "option":
v := &Option{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
case "result":
v := &Result{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "list":
v := &List{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
case "future":
v := &Future{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
case "stream":
v := &Stream{}
err, *c.v = dec.Decode(v), v
err = dec.Decode(v)
*c.v = v
case "type":
var v Type
err, *c.v = dec.Decode(&v), v
err = dec.Decode(&v)
*c.v = v
}
return err
}
Expand Down Expand Up @@ -404,10 +422,12 @@ func (c *handleCodec) DecodeField(dec codec.Decoder, name string) error {
switch name {
case "own":
v := &OwnedHandle{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
case "borrow":
v := &BorrowedHandle{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
}
return err
}
Expand Down Expand Up @@ -493,13 +513,16 @@ func (c *functionKindCodec) DecodeField(dec codec.Decoder, name string) error {
switch name {
case "method":
v := &Method{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
case "static":
v := &Static{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
case "constructor":
v := &Constructor{}
err, *c.v = dec.Decode(&v.Type), v
err = dec.Decode(&v.Type)
*c.v = v
}
return err
}
Expand Down