[Issue 14269] Enum is not implicitly converted to base type when using ref
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Mar 12 12:15:32 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14269
--- Comment #29 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
(In reply to Steven Schveighoffer from comment #24)
> (In reply to Jonathan M Davis from comment #22)
> > I think that allowing an implicit conversion to be used with a ref parameter
> > is a clear violation of the type system.
>
> class C {}
>
> void foo(Object o);
>
> void main()
> {
> C c = new C;
> foo(c); // works, and passed by ref!
> }
>
> I think clearly there is a similar relationship with enums and their base
> type.
In that case, you're not passing by ref. You're dealing with a reference type -
and a polymorphic one at that. There is nothing polymorphic about enums unless
they happen to have a class type as their base type. And this code does _not_
compile:
class C {}
void foo(ref Object o);
void main()
{
C c = new C;
foo(c);
}
ref and class references are not the same thing at all.
--
More information about the Digitalmars-d-bugs
mailing list