D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2995 - Incorrect conversion in c ? a : b
Summary: Incorrect conversion in c ? a : b
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2009-05-16 21:41 UTC by Andrei Alexandrescu
Modified: 2014-02-15 02:46 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-05-16 21:41:20 UTC
class A {}

void main()
{
    immutable(A) b;
    A c;
    auto z = true ? b : c;
    writeln(typeof(z).stringof);
}

writes Object, which is wrong in a number of ways. The common type of A and immutable(A) is const(A).
Comment 1 Don 2010-04-04 08:22:46 UTC
PATCH: cast.c, line 1663. Conversion of both types to const needs to occur for classes, as well as for arrays and pointers.

    else if (t1->ty == Tclass || t2->ty == Tclass)
    {
+        if (t1->mod != t2->mod)
+        {
+            t1 = t1->mutableOf()->constOf();
+            t2 = t2->mutableOf()->constOf();
+            t = t1;
+            goto Lagain;
+        }
        while (1)
        {
            int i1 = e2->implicitConvTo(t1);
            int i2 = e1->implicitConvTo(t2);
Comment 2 Don 2010-05-05 19:19:37 UTC
Fixed DMD2.044.