#2758 @Serializable, non-const classes, and it-block ctors

SlimerDude Wed 26 Jun

When I try to de-serialise a non-const class with an it-block ctor, I get an error. Here's a side by side example with a const class:

const class ConstClass {
    const Str name
    new make(|This| f) { f(this) }

class NotConstClass {
    Str name
    new make(|This| f) { f(this) }

constClass    := ConstClass    { it.name = "wotever" }
notConstClass := NotConstClass { it.name = "wotever" }
serial1 := Buf().writeObj(constClass)
serial1.flip.readObj  // --> okay

serial2 := Buf().writeObj(notConstClass)
serial2.flip.readObj  // --> ERROR!

sys::ArgErr: Too few arguments: 0 < 1..1
  fan.sys.Method$MethodFunc.checkArgs (Method.java:520)
  fan.sys.Method$MethodFunc.callList (Method.java:206)
  fan.sys.Method.callList (Method.java:138)
  fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:246)
  fanx.serial.ObjDecoder.readObj (ObjDecoder.java:146)
  fanx.serial.ObjDecoder.readObj (ObjDecoder.java:55)
  fan.sys.InStream.readObj (InStream.java:641)
  fan.sys.InStream.readObj (InStream.java:638)
  fan.sys.Buf.readObj (Buf.java:358)

It seems the it-block is being ignored because it is a normal class - but given the class has non-nullable fields, the it-block ctor is the only workable choice.

Login or Signup to reply.