Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3085 from klickverbot/pure-return-immutable
pure -> immutable fixes
- Loading branch information
Showing
7 changed files
with
106 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
struct S | ||
{ | ||
immutable(S)* s; | ||
this(int) immutable pure | ||
{ | ||
s = &this; | ||
} | ||
int data; | ||
} | ||
|
||
immutable(S)* makes() pure | ||
{ | ||
return new immutable S(0); | ||
} | ||
|
||
void main() | ||
{ | ||
S* s = makes(); // s is mutable and contains an immutable reference to itself | ||
//s.s.data = 7; // this is immutable | ||
s.data = 3; // but this is not!!! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
immutable int[] x = [1, 2, 3]; | ||
|
||
auto makes() pure | ||
{ | ||
return x; | ||
} | ||
|
||
int main() | ||
{ | ||
auto a = x; | ||
int[] b = makes(); | ||
return b[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
struct Data | ||
{ | ||
char[256] buffer; | ||
@property const(char)[] filename() const pure nothrow | ||
{ | ||
return buffer[]; | ||
} | ||
} | ||
|
||
void main() | ||
{ | ||
Data d; | ||
string f = d.filename; | ||
d.buffer[0] = 'a'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
struct Data2 | ||
{ | ||
char buffer; | ||
} | ||
|
||
@property const(char)[] filename(const ref Data2 d) pure nothrow | ||
{ | ||
return (&d.buffer)[0 .. 1]; | ||
} | ||
|
||
@property const(char)[] filename2(const Data2* d) pure nothrow | ||
{ | ||
return (&d.buffer)[0 .. 1]; | ||
} | ||
|
||
void main() | ||
{ | ||
Data2 d; | ||
string f = d.filename; | ||
string g = (&d).filename2; | ||
d.buffer = 'a'; | ||
} |