D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1417 - templated final const member can't be assigned in constructor from the const const argument
Summary: templated final const member can't be assigned in constructor from the const ...
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: rejects-valid
Depends on: 1410
Blocks:
  Show dependency treegraph
 
Reported: 2007-08-13 00:32 UTC by Witold Baryluk
Modified: 2015-06-09 01:14 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Witold Baryluk 2007-08-13 00:32:04 UTC
----
import std.stdio;

class B(T) {
        T z;
        this(T _z) {
                z = _z;
        }
}

alias B!(int) Bi;
alias const(B!(int)) Bic;

//static assert(!(is(typeof(Bi) == typeof(Bi)))); // fails! (see #1410)

class A {
        // final const(Bi) x;    // works
        // final const(Bic) x;    // works
        final const(B!(int)) x;    // doesn't
        // final Bic x;               // also doesn't (see #1410)

        this(const const(B!(int)) b) {
                x = b; // Error: cannot implicitly convert expression (_x) 
                                // of type const B to pr3.B!(int).B
                // x.z = 0; // fails. good
        }

        const void print() {
                writefln(x.z);
        }

        //void print2() {
                //x = new const(B!(int))(6) // fails. good
                //x.z = 6; // fails. good
        //}
}

void main() {
        const(B!(int)) b = new const(B!(int))(5);
        A a = new A(b);
        a.print(); // prints 5
}
----


similar problem:

----
class B(T) {
        T z;
}

alias B!(int) Bi;
alias const(B!(int)) Bic;

//static assert(!(is(typeof(Bi) == typeof(Bi)))); // fails! (see #1410)

class A {
        // final const(Bi) x;    // works
        // final const(Bic) x;    // works
        final const(B!(int)) x;    // doesn't
        // final Bic x;               // also doesn't (see #1410)
        // const(B!(int)) x;    // works
        this() {
                x = new const(Bi)(); // Error: cannot implicitly convert expression (_x) 
                                // of type const B to pr3.B!(int).B
                // x = new const(B!(int))(); // works
        }

}

void main() {
        A a = new A();
}
----

This bug prevents writing strictly const code with templates.
Comment 1 Witold Baryluk 2009-11-18 13:27:44 UTC
Closing, as #1410 is already working correctly, and I think this also. Tested in v2.032. Probably working since 2.022.
Comment 2 Witold Baryluk 2009-11-18 13:28:20 UTC
Closing, as #1410 is already working correctly, and I think this also. Tested in v2.032. Probably working since 2.022.