Chaining Methods in ABL not working - A known bug?

Posted by cwills on 03-Feb-2010 18:21

I am trying to create a class that will support the chaining of methods. See the simple class definition below...

USING Test.*.


CLASS Test.Chain:


  /* Static method */

  METHOD PUBLIC STATIC Chain NewChain():

    RETURN NEW Chain().

  END METHOD.

 

  METHOD PUBLIC Chain Link():

    RETURN THIS-OBJECT.   

  END METHOD.


END CLASS.

When I run the code below I get an error... "Lead attributes in a chained-attribute expression (a:b:c) must be type HANDLE or a user-defined type and valid (not UNKNOWN). (10068)"

USING Test.*.


DEFINE VARIABLE chn AS Chain NO-UNDO.


chn = Chain:NewChain():Link():Link():Link():Link().

Is this a known issue? From my knowledge of OOABL and it's caveats, this code should work...

I am running OpenEdge 10.2A02 on Windows 7.

All Replies

Posted by Admin on 03-Feb-2010 23:24

Interesting. I tested this on 10.2B and it looks like the first call to Link() succeds and the second is the one that fails.

My asssumption is, that the AVM Garbage Collector is too fast with removing the one instance you are dealing with. I've rewritten the test procedure to create the one instance using a constructor, not the NewChain() static method. This way it keeps a reference to the one instance in chn2 as well and the code succeeds.

USING Test.*.

DEFINE VARIABLE chn AS Chain NO-UNDO.

DEFINE VARIABLE chn2 AS Chain NO-UNDO.

chn2 = NEW Chain () .

chn = chn2:Link():Link():Link():Link().

Did you already report that to tech support? It looks very suspicious.

Posted by cwills on 05-Feb-2010 23:14

Yes your code works. As does:


(NEW Chain()):Link():Link():Link():Link().

But neither of these solutions are exactly what I'm looking for... I really need the static factory method and all subsequent calls to 'Link()' to be in the same statement.

I'll report this issue to tech support. Thanks for taking a look.

Posted by Thomas Mercer-Hursh on 06-Feb-2010 11:15

While I'm not sure what the issue is here, I would be very interested in hearing your use case.  I suppose I have a built-in suspicion of statics ... not that they aren't extremely useful in their place ... and I'm curious about any given use case and whether or not I would be inclined to solve it the same way.  I.e., for starters, what is it that makes you "need" your solution over Mike's?

Posted by cwills on 08-Feb-2010 04:45

I'm prototyping some ideas I have for an internal DSL (http://martinfowler.com/dslwip/InternalOverview.html) written in OOABL.

I'm trying to implement a Fluent API using Method Chaining (http://martinfowler.com/dslwip/MethodChaining.html)

I wont go into specifics, suffice to say that chained statements written with my API would be much more 'fluent' if I could start them with a static factory method (e.g. something like Chain:NewChain() ).

I guess I should say this question has been answered, as this appears to be a bug in the OE runtime.

I feel that the example above in my original post should work...Irrespective of any workarounds I/we can come up with.

Posted by Admin on 08-Feb-2010 06:03

I guess I should say this question has been answered, as this appears to be a bug in the OE runtime.

I feel that the example above in my original post should work...Irrespective of any workarounds I/we can come up with.

Please keep us updated about what tech support says about this!

Posted by cwills on 16-Feb-2010 18:33

I got a response from Progress Support saying this has been acknowledged as a bug.

"After sending this issue you reported to Development, they have acknowledged this is a bug. I have filed OE00195481 for it. The bug is currently marked as Normal Priority by the development and is scheduled to be looked into in Release 11."


Posted by Thomas Mercer-Hursh on 16-Feb-2010 18:52

I guess they must not think too many people will try to do what you did ...

This thread is closed