On 18.05.2022 15:29, Rick McGuire wrote:


On Wed, May 18, 2022 at 8:45 AM Rony G. Flatscher <rony.flatsc...@wu.ac.at> 
wrote:


... cut ...

    ObjectClass.cpp defines validateScopeOverride() as:

        /**
          * Validate a scope override on a message send.
          *
          * @param scope  The scope we're checking.
          */
        void RexxObject::validateScopeOverride(RexxClass *scope)
        {
             if (scope != OREF_NULL)
             {
                 if (!isInstanceOf(scope))
                 {
                     reportException(Error_Incorrect_method_array_noclass, 
this, scope);
                 }
             }
        }

    Should ObjectClass.validateScopeOverride() be changed to check in addition whether 
"this" is a
    class object and if so, use maybe isSubClassOrEnhanced() instead of 
isInstanceOf()?

    If so, what would be the best approach, the best code for this?

Ok, I see what's going on here. This is failing because isInstanceOf() is a real instance of check. The class is not itself an instance of the itself, so o~isA(.mixin2) returns .false, which is the correct answer.  However, class objects can still have methods at the requested scope even though they are not instances. I suspect the best approach is to remove this check altogether and just fall back to reporting "Method not found". However, this certainly can be improved by using a new version of the method that includes the requested scope information in the error.

What about some version that first tests for isInstanceOf() and if that fails checks whether receiver is a class object and if so whether it is a subclass, something like:

   /**
     * Validate a scope override on a message send.
     *
     * @param scope  The scope we're checking.
     */
   void RexxObject::validateScopeOverride(RexxClass *scope)
   {
        if (scope != OREF_NULL)
        {
            if (!isInstanceOf(scope))
            {
                if (isInstanceOf(TheClassClass))
                {
                    if (!((RexxClass *)scope)->isSubClassOf(scope))
                    {
                        reportException(Error_Incorrect_method_array_noclass, 
this, scope);
                    }
                }
                else
                {
                    reportException(Error_Incorrect_method_array_noclass, this, 
scope);
                }
            }
        }
   }

The above does not work as compiling would issue:

   F:\work\svn\oorexx\main\trunk\interpreter\classes\ObjectClass.cpp(1971): 
error C2039: 'isSubClassOf': is not a member of 'RexxClass'
   f:\work\svn\oorexx\main\trunk\interpreter\classes\MethodClass.hpp(55): note: 
see declaration of 'RexxClass'
   NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return 
code '0x2'

Found 'isSubClassOf' in:

   interpreter/classes/ClassClass.cpp:1692:RexxObject 
*RexxClass::isSubclassOf(RexxClass *other)
   interpreter/classes/ClassClass.hpp:138:    RexxObject 
*isSubclassOf(RexxClass *other);
   interpreter/execution/CPPCode.cpp:735:    CPPM(RexxClass::isSubclassOf),
   interpreter/memory/Setup.cpp:480:        AddMethod("IsSubclassOf", 
RexxClass::isSubclassOf, 1);

---rony


_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to