Bug 12909 – [AA] Function is incorrectly inferred as strongly pure for associative array with key of non-mutable array or pointer as argument

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-13T09:08:00Z
Last change time
2014-06-14T15:37:15Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
verylonglogin.reg
Blocks
12910

Comments

Comment #0 by verylonglogin.reg — 2014-06-13T09:08:49Z
This code should compile without warnings: --- int f(immutable(int[])[int] a) pure nothrow { a[0] = []; return 0; } void main() { immutable(int[])[int] aa; aa.f(); } --- main.d(10): Warning: calling main.f without side effects discards return value of type int, prepend a cast(void) if intentional --- This is a major issue as it creates release-only bugs also depending on `-inline` switch as optimizer can not call such functions if it isn't already inlined: --- import std.stdio; void f(immutable(string)[int] a) pure nothrow { // This `try` is needed to prevent inlining if compiled // with `-inline`: try debug writeln("f called."); catch { } a[1] = "a"; } void main() { immutable(string)[int] aa = [0 : ""]; aa.f(); writeln(aa); } --- Writes `[0:""]` if optimized.
Comment #1 by verylonglogin.reg — 2014-06-13T09:23:39Z
Correction: The issue is triggered in case of AA key being a non-mutable array or pointer, e.g.: `const(int[])[int]` or `const(int*)[int]`.
Comment #2 by k.hara.pg — 2014-06-14T12:00:59Z
Comment #3 by github-bugzilla — 2014-06-14T15:37:12Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/20feb28801935b27cc26df279de09f14abaa8509 fix Issue 12909 - [AA] Function is incorrectly inferred as strongly pure for associative array with key of non-mutable array or pointer as argument https://github.com/D-Programming-Language/dmd/commit/27fc0660064d0ba0acc34081165e806d8afec8f2 Merge pull request #3667 from 9rnsr/fix12909 Issue 12909 & 12910 - fix purity level calculation for AA parameter