"Fossies" - the Fresh Open Source Software Archive

Member "dmd-2.089.1/test/fail_compilation/fail18719.d" (14 Dec 2019, 656 Bytes) of package /linux/misc/dmd-2.089.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) D source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "fail18719.d": 2.087.1_vs_2.088.0.

    1 // https://issues.dlang.org/show_bug.cgi?id=18719
    2 
    3 // REQUIRED_ARGS:
    4 /*
    5 TEST_OUTPUT:
    6 ---
    7 fail_compilation/fail18719.d(30): Error: immutable field `x` initialized multiple times
    8        Previous initialization is here.
    9 ---
   10 */
   11 
   12 struct S
   13 {
   14     int x = -1;
   15     this(int y) immutable
   16     {
   17         x = y;
   18         import core.stdc.stdio;
   19         printf("Ctor called with %d\n", y);
   20     }
   21     void opAssign(int) immutable;
   22 }
   23 
   24 class C
   25 {
   26     S x;
   27     this() immutable
   28     {
   29         this(42); /* Initializes x. */
   30         x = 13; /* Breaking immutable, or ok? */
   31     }
   32     this(int x) immutable
   33     {
   34         this.x = x;
   35     }
   36 }
   37 
   38 void main()
   39 {
   40     new immutable C;
   41 }