[Issue 15660] break immutable with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 github-bugzi...@puremagic.com changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --
[Issue 15660] break immutable with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 --- Comment #8 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/ab5a18635adaa3e2271e0f4b569500a89ac74235 fix Issue 15660 - break immutable with pure function and mutable reference params https://github.com/dlang/dmd/commit/54ab04e0ab6d27d96c78eccf10bc162fd08535cf Merge pull request #8048 from WalterBright/fix15660 fix Issue 15660 - break immutable with pure function and mutable refeā¦ merged-on-behalf-of: Walter Bright <walterbri...@users.noreply.github.com> --
[Issue 15660] break immutable with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 --- Comment #7 from Walter Bright--- https://github.com/dlang/dmd/pull/8048 --
[Issue 15660] break immutable with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 Walter Brightchanged: What|Removed |Added Summary|break "immutable" with pure |break immutable with pure |function and mutable|function and mutable |reference params|reference params --
[Issue 15660] break "immutable" with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 Walter Brightchanged: What|Removed |Added CC||bugzi...@digitalmars.com --- Comment #6 from Walter Bright --- (In reply to Steven Schveighoffer from comment #4) > (In reply to Iakh from comment #3) > > (In reply to Steven Schveighoffer from comment #2) > > Even this works: > > import std.stdio; > > > > int[] f(void[] a) @safe pure > > { > > return cast(int[])a; > > } > > In this case, you are using a cast. The compiler pretty much gives up trying > to ensure anything when you cast, so I think it's OK to allow that. > > Although, I thought such a cast wouldn't work in @safe code. And indeed, it no longer is compilable: test.d(3): Error: cast from void[] to int[] not allowed in safe code --
[Issue 15660] break "immutable" with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 Iakhchanged: What|Removed |Added Keywords||safe --
[Issue 15660] break "immutable" with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 --- Comment #4 from Steven Schveighoffer--- (In reply to Iakh from comment #3) > (In reply to Steven Schveighoffer from comment #2) > Even this works: > import std.stdio; > > int[] f(void[] a) @safe pure > { > return cast(int[])a; > } In this case, you are using a cast. The compiler pretty much gives up trying to ensure anything when you cast, so I think it's OK to allow that. Although, I thought such a cast wouldn't work in @safe code. --
[Issue 15660] break "immutable" with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 Steven Schveighofferchanged: What|Removed |Added Summary|breack "immutable" with |break "immutable" with pure |pure function and mutable |function and mutable |params |reference params --
[Issue 15660] break "immutable" with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 --- Comment #5 from Iakh--- (In reply to Steven Schveighoffer from comment #4) > In this case, you are using a cast. The compiler pretty much gives up trying > to ensure anything when you cast, so I think it's OK to allow that. > > Although, I thought such a cast wouldn't work in @safe code. Me too. Casting of array types does in reinterpret_cast manner. So it's a bug in @safe definition. --
[Issue 15660] break "immutable" with pure function and mutable reference params
https://issues.dlang.org/show_bug.cgi?id=15660 Iakhchanged: What|Removed |Added URL||http://forum.dlang.org/thre ||ad/rdiwdveqfhevqugddwwd@for ||um.dlang.org --- Comment #3 from Iakh --- (In reply to Steven Schveighoffer from comment #2) Even this works: import std.stdio; int[] f(void[] a) @safe pure { return cast(int[])a; } void main() @safe { int[] a = new int[4]; immutable b = a.f(); writeln(b); a[0] = 1; writeln(b); } > One significant problem here is that the compiler may not consider the > parameter to f in these cases to be a *return* avenue, only a parameter. The > compiler should take into account references to ensure that they cannot > escape the same data that is being returned. So not only escape. Compiler just traverses params's AST and search for exactly match with ReturnType. > Fixing this may break a lot of code, but probably for the better. May need a > deprecation cycle for this. --