Discussion:
Can someone explain why reducing visibility generates catcalls?
(too old to reply)
llothar
2010-09-10 11:36:41 UTC
Permalink
I can't find any example how reducing visibility by using the export
clause feature during inheritance can result in a catcall.
Martin Piskernig
2010-09-10 21:03:35 UTC
Permalink
Post by llothar
I can't find any example how reducing visibility by using the export
clause feature during inheritance can result in a catcall.
An example:

class A
feature
proc do end
end

class B
inherit A export {NONE} proc end
end

Somewhere in your code:
a:A
b:B
...
a.proc; -- ok
b.proc; -- forbidden
a := b; -- polymorphic attachment
a.proc -- aaargh!

When a.proc is executed, really B's proc will be called
at runtime - however, this is not allowed according to
the class declaration of B. So we have a CATcall because of
changed access and thus a hole in the type system. At least
it usually won't crash ;-)

Narrowing down access rights in descendants cries for
problems because B is now only a subclass, not a subtype of A.

AFAIR the ECMA standard joins all exports of a feature,
so actually B.proc would be exported to {ANY,NONE}. It's not
intuitive, but at least it is a solution.

CATcalls because of covariant type redefinition is still not
solved in any way -- and IMHO it can't, without sacrificing a
lot of Eiffel's flexibility.

Martin
llothar
2010-09-10 22:21:29 UTC
Permalink
Post by Martin Piskernig
When a.proc is executed, really B's proc will be called
at runtime - however, this is not allowed according to
the class declaration of B. So we have a CATcall because of
changed access and thus a hole in the type system. At least
it usually won't crash ;-)
Thanks. There was some CATcall == crash in my mind, so i didn't
see this.

By the way which other (alive) languages are using covariant
parameter redefinitions? I know that Java and C# 4.0 allow them
in Generics.
Martin Piskernig
2010-09-12 21:46:10 UTC
Permalink
Post by llothar
By the way which other (alive) languages are using covariant
parameter redefinitions?
AFAIK, there is no other statically typed language allowing
this. Beta had virtual types which could be used to covariantly
redefine parameters. However, when you count only alive
languages, I think there isn't even a single example apart from
Eiffel.

Covariance and the various "resolutions" to its type holes
is one of the less glorious chapters of this otherwise great
language. Recent work by Helmut Brandl (tecomp) seems
promising - if it's not too restricting in practice.
Post by llothar
I know that Java and C# 4.0 allow them in Generics.
Scala allows this, too. But, as the subtype relationship is
obeyed in these languages, every use of type parameters is
garantueed statically correct by the following restrictions:
- Covariant type parameters may only be used as method
result types.
- Contravariant type parameters may only be used as method
parameter types.

Martin

Loading...