Overwriting hidden methods: X# vs VO

This forum is meant for questions and discussions about the X# language and tools
Post Reply
stefan.ungemach
Posts: 71
Joined: Thu Jul 15, 2021 10:46 am
Location: Germany

Overwriting hidden methods: X# vs VO

Post by stefan.ungemach »

The following Code

class MySuperClass
constructor
self:_setup()
hidden method _setup()
Safedebout32("mysuperclass",classname(self))
return
end class

class MySubClass inherit MySuperClass
hidden method _setup()
Safedebout32("mysubclass",classname(self))
return
end class

function TestCode() as usual clipper
local o as MySubClass

o := MySubClass{}
return

arrives at the green Line in VO and at the red line in X#. Do we really need to refactor all these occurences or is there some switch to enable VO-like behaviour in this case?

P.S.: If I omit the HIDDEN statement the behaviour is the same in both languages.
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Overwriting hidden methods: X# vs VO

Post by Chris »

Hi Stefan,

I think that's a bug in VO. By definition a HIDDEN (or PRIVATE as is usually called in .Net) method is only visible in the same class that it is declared in and completely invisible from anywhere else, including subclasses, so it cannot be called from the child constructor. Why had you defined the methods as HIDDEN, maybe you intended to define them as PROTECTED?

(not blaming you, I know that due to its very sloppy compiler VO allowed a lot of things to compile and work at runtime in a way that they never should had. X# revealed a lot of similar issues in my VO code, and everybody else's basically)
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Overwriting hidden methods: X# vs VO

Post by robert »

Stefan,
In VO all methods are virtual. Apparently this means that you can override a hidden method.
In .Net private methods are never virtual (because they cannot be overwritten in subclasses).

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
stefan.ungemach
Posts: 71
Joined: Thu Jul 15, 2021 10:46 am
Location: Germany

Overwriting hidden methods: X# vs VO

Post by stefan.ungemach »

Thanks for clarifying. Unfortunately this special construct is Part of one of our most used design patterns which means that we should probably remote all our "hidden" Statements in Vo before continuing the migration...
VR
Posts: 102
Joined: Sun Aug 23, 2020 3:07 pm
Location: Italy

Overwriting hidden methods: X# vs VO

Post by VR »

Instead of removing the Hidden Modifier, you could consider replacing it with the Proteced modifier.

Protected methods can be overridden but are only visible to class and all inherited classes but as hidden methods, they can not be called from other classes.

Volkmar
Post Reply