#1185 Curious why this code fails

yachris Sat 28 Aug 2010

Hello,

using concurrent

const class TryMultiActors : Actor
{
    Void main(Str[] args)
    {
        echo("Jello, whirled!")
        pool := ActorPool()
        tma1 := TryMultiActors(pool)
        tma2 := TryMultiActors(pool)
        fut1 := tma1.send("First")
        fut2 := tma2.send("Second")
        echo("tma1 returns " + fut1.get)
        echo("tma2 returns " + fut2.get)
    }

    new make(ActorPool p) : super(p)
    {
    }

    override Obj? receive(Obj? msg)
    {
        echo(msg)
        return 11
    }
}

Compiles fine, but when I try to run it, I get:

sys::Err: Type missing 'make' or 'defVal' slots: fantest::TryMultiActors
fan.sys.Type.make (Type.java:254)
fan.sys.ClassType.make (ClassType.java:110)
fan.sys.Type.make (Type.java:234)
fanx.tools.Fan.callMain (Fan.java:137)
fanx.tools.Fan.executeType (Fan.java:102)
fanx.tools.Fan.execute (Fan.java:38)
fanx.tools.Fan.run (Fan.java:236)
fanx.tools.Fan.main (Fan.java:274)

Changing the make declaration to:

new make(ActorPool p := ActorPool()) : super(p)

causes it to compile and run just fine. Clues please? This doesn't match the example on the Actors page.

Thanks!

vkuzkokov Sat 28 Aug 2010

It's about how fan runs classes

  1. Static main works pretty much like in java, otherwise:
  2. Try to get default instance from defVal
  3. Or create new one calling constructor make and no arguments.

What meant on Actors page is that you can use properly created instance in described manner. Not that it can be created with no args.

brian Sat 28 Aug 2010

Yeah you just need to change your main routine to be static. Fantom actually allows your main to be instance based, but then you have to provide a no-arg public make constructor (which your example lacks).

Login or Signup to reply.