www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Covariance doesn't work on forward-referenced classes

reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Using DMD 0.111, Windows 98SE.

The compiler refuses to accept a covariant return type that is forward 
referenced.  Hence it is impossible for two classes to use each other as 
covariant return types (unless one is nested within the other).

----------
class Qwert {
     Qwert yuiop() { return new Qwert; }
}

class Asdfg : Qwert {
     override Hjkl yuiop() { return new Hjkl; }
}

class Hjkl : Qwert {
     override Asdfg yuiop() { return new Asdfg; }
}
----------
D:\My Documents\Programming\D\Tests\bugs\covariant3.d(6): function 
covariant3.Asdfg.yuiop of type Hjkl () overrides but is not covariant 
with covariant3.Qwert.yuiop of type Qwert ()
----------

The same occurs if the two classes are defined in separate modules (in 
which case compiling module A reports an error in module B, and vice versa).

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
Feb 11 2005
parent reply =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.THISISSPAM.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon wrote:

| Using DMD 0.111, Windows 98SE.
|
| The compiler refuses to accept a covariant return type that is forward
| referenced.  Hence it is impossible for two classes to use each other as
| covariant return types (unless one is nested within the other).
|
| ----------
| class Qwert {
|     Qwert yuiop() { return new Qwert; }
| }
|
| class Asdfg : Qwert {
|     override Hjkl yuiop() { return new Hjkl; }
| }
|
| class Hjkl : Qwert {
|     override Asdfg yuiop() { return new Asdfg; }
| }
| ----------
| D:\My Documents\Programming\D\Tests\bugs\covariant3.d(6): function
| covariant3.Asdfg.yuiop of type Hjkl () overrides but is not covariant
| with covariant3.Qwert.yuiop of type Qwert ()
| ----------
|
| The same occurs if the two classes are defined in separate modules (in
| which case compiling module A reports an error in module B, and vice
| versa).
|
| Stewart.
|

Added to DStress as
http://dstres.kuehne.cn/run/overload_17.d
http://dstres.kuehne.cn/run/overload_18.d

Thomas

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCDUwi3w+/yD4P9tIRAj5oAKCeiV2W94Hyp9aKPAqMHEkl10ZCRwCfXMcV
Rum0wJuLym6iAJJJjV8EVBk=
=HfCU
-----END PGP SIGNATURE-----
Feb 11 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Thomas Kühne wrote:
<snip>
 Added to DStress as
 http://dstres.kuehne.cn/run/overload_17.d
 http://dstres.kuehne.cn/run/overload_18.d
Surely this is override, not overload? Or are you using "override" to mean issues specific to the override keyword? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Feb 14 2005
parent =?ISO-8859-1?Q?Thomas_K=FChne?= <thomas-dloop kuehne.THISISSPAM.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon wrote:
| Thomas Kühne wrote:
| <snip>
|
|> Added to DStress as
|> http://dstress.kuehne.cn/run/overload_17.d
|> http://dstress.kuehne.cn/run/overload_18.d
|
| Surely this is override, not overload?  Or are you using "override" to
| mean issues specific to the override keyword?

"override" is specific to the "override" keyword.
"overload" contains general problems with functions' signatures.

Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCFl9X3w+/yD4P9tIRAvWpAJ9DZC+6YHKc8fIEK+fLLDMCOk0RawCfWeOe
wJ0FZdvr/UUA4uknSS8GidM=
=YuMV
-----END PGP SIGNATURE-----
Feb 18 2005