#1715 Problem with concurrent example code

theGeeko61 Wed 30 Nov 2011

I am trying this example from the documentation:

1] pool := ActorPool()

2] a := Actor(pool) |msg|

3] {

4] count := 1 + Actor.locals.get("count", 0)

5] Actor.locals["count"] = count

6] return count

7] }

8] 100.times { a.send("ignored") }

9] echo("Count is now " + a.send("ignored").get)

But I am getting a compile-time error on line 4]:

Ambiguous operator method: sys::Int + sys::Obj? (plus, plusFloat, plusDecimal)

andy Wed 30 Nov 2011

Hey theGeeko61 - Actor.locals is going to return as typed Obj so you just need to cast to an Int:

count := 1 + (Int)Actor.locals.get("count", 0)

Assume you saw this here: /doc/docLang/Actors.html#locals? I will fix.

qualidafial Wed 30 Nov 2011

I know you got this code from the docs, but I'll go ahead and explain whats wrong for anyone who might also see this error:

Actor.locals.get(Str,Obj?) returns type Obj?.

So when you use the expression:

1 + Actor.locals.get("count", 0)

The compiler, knowing that 1 is an Int, searches Int for a method named "plus" or "plus<something>", with an @Operator facet, which takes an Obj or Obj? as its only argument.

There is no such method in Int.

You could help the compiler see what you're doing by casting the right hand side to Int:

1 + (Int) Actor.locals.get("count", 0)

brian Wed 30 Nov 2011

There is no such method in Int.

Actually the problem is that they are three potential methods plus, plusFloat, and plusDecimal which makes it ambiguous.

That code used to work, but it gotten broken when I fixed ticket 604. This sample code slipped thru the cracks. Thanks for reporting

theGeeko61 Wed 30 Nov 2011

Thanks for the quick response... meanwhile, I moved on to the Examples... where the cast is explicitly made...

I returned here to update my post... but you folks are too fast!! LOL

It's a good thing.

Login or Signup to reply.