mirror of https://github.com/k3s-io/k3s
deep-copies: Structs cannot be nil
parent
8e25b7c7bf
commit
ef36b3e4f6
|
@ -2267,8 +2267,6 @@ func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c
|
|||
if in.Amount != nil {
|
||||
if newVal, err := c.DeepCopy(in.Amount); err != nil {
|
||||
return err
|
||||
} else if newVal == nil {
|
||||
out.Amount = nil
|
||||
} else {
|
||||
out.Amount = newVal.(*inf.Dec)
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c
|
|||
if in.Amount != nil {
|
||||
if newVal, err := c.DeepCopy(in.Amount); err != nil {
|
||||
return err
|
||||
} else if newVal == nil {
|
||||
out.Amount = nil
|
||||
} else {
|
||||
out.Amount = newVal.(*inf.Dec)
|
||||
}
|
||||
|
|
|
@ -809,8 +809,6 @@ func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c
|
|||
if in.Amount != nil {
|
||||
if newVal, err := c.DeepCopy(in.Amount); err != nil {
|
||||
return err
|
||||
} else if newVal == nil {
|
||||
out.Amount = nil
|
||||
} else {
|
||||
out.Amount = newVal.(*inf.Dec)
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c
|
|||
if in.Amount != nil {
|
||||
if newVal, err := c.DeepCopy(in.Amount); err != nil {
|
||||
return err
|
||||
} else if newVal == nil {
|
||||
out.Amount = nil
|
||||
} else {
|
||||
out.Amount = newVal.(*inf.Dec)
|
||||
}
|
||||
|
|
|
@ -403,7 +403,8 @@ func (g *deepCopyGenerator) writeDeepCopyForPtr(b *buffer, inField reflect.Struc
|
|||
ifStmt := fmt.Sprintf(ifFormat, inField.Name)
|
||||
b.addLine(ifStmt, indent)
|
||||
|
||||
switch inField.Type.Elem().Kind() {
|
||||
kind := inField.Type.Elem().Kind()
|
||||
switch kind {
|
||||
case reflect.Map, reflect.Ptr, reflect.Slice, reflect.Interface, reflect.Struct:
|
||||
if _, found := g.copyables[inField.Type.Elem()]; found {
|
||||
newFormat := "out.%s = new(%s)\n"
|
||||
|
@ -420,8 +421,10 @@ func (g *deepCopyGenerator) writeDeepCopyForPtr(b *buffer, inField reflect.Struc
|
|||
ifStmt := fmt.Sprintf(ifFormat, inField.Name)
|
||||
b.addLine(ifStmt, indent+1)
|
||||
b.addLine("return err\n", indent+2)
|
||||
b.addLine("} else if newVal == nil {\n", indent+1)
|
||||
b.addLine(fmt.Sprintf("out.%s = nil\n", inField.Name), indent+2)
|
||||
if kind != reflect.Struct {
|
||||
b.addLine("} else if newVal == nil {\n", indent+1)
|
||||
b.addLine(fmt.Sprintf("out.%s = nil\n", inField.Name), indent+2)
|
||||
}
|
||||
b.addLine("} else {\n", indent+1)
|
||||
assignFormat := "out.%s = newVal.(%s)\n"
|
||||
assignStmt := fmt.Sprintf(assignFormat, inField.Name, g.typeName(inField.Type))
|
||||
|
@ -455,7 +458,8 @@ func (g *deepCopyGenerator) writeDeepCopyForSlice(b *buffer, inField reflect.Str
|
|||
forStmt := fmt.Sprintf(forFormat, inField.Name)
|
||||
b.addLine(forStmt, indent+1)
|
||||
|
||||
switch inField.Type.Elem().Kind() {
|
||||
kind := inField.Type.Elem().Kind()
|
||||
switch kind {
|
||||
case reflect.Map, reflect.Ptr, reflect.Slice, reflect.Interface, reflect.Struct:
|
||||
if _, found := g.copyables[inField.Type.Elem()]; found {
|
||||
assignFormat := "if err := %s(in.%s[i], &out.%s[i], c); err != nil {\n"
|
||||
|
@ -469,8 +473,10 @@ func (g *deepCopyGenerator) writeDeepCopyForSlice(b *buffer, inField reflect.Str
|
|||
ifStmt := fmt.Sprintf(ifFormat, inField.Name)
|
||||
b.addLine(ifStmt, indent+2)
|
||||
b.addLine("return err\n", indent+3)
|
||||
b.addLine("} else if newVal == nil {\n", indent+2)
|
||||
b.addLine(fmt.Sprintf("out.%s[i] = nil\n", inField.Name), indent+3)
|
||||
if kind != reflect.Struct {
|
||||
b.addLine("} else if newVal == nil {\n", indent+2)
|
||||
b.addLine(fmt.Sprintf("out.%s[i] = nil\n", inField.Name), indent+3)
|
||||
}
|
||||
b.addLine("} else {\n", indent+2)
|
||||
assignFormat := "out.%s[i] = newVal.(%s)\n"
|
||||
assignStmt := fmt.Sprintf(assignFormat, inField.Name, g.typeName(inField.Type.Elem()))
|
||||
|
|
Loading…
Reference in New Issue