Bug 12568 – std.functional.memoize with constant array argument too

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-12T22:13:00Z
Last change time
2014-04-25T19:48:23Z
Keywords
pull, rejects-valid
Assigned to
andrej.mitrovich
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-04-12T22:13:07Z
I'd like the len2 function to compile: import std.functional: memoize; uint len1(string s) { // OK alias mLen1 = memoize!len1; if (s.length == 0) return 0; else return 1 + mLen1(s[1 .. $]); } uint len2(const string s) { // Error alias mLen2 = memoize!len2; if (s.length == 0) return 0; else return 1 + mLen2(s[1 .. $]); } void main() {} DMD 2.066alpha gives: ...\dmd2\src\phobos\std\functional.d(674,18): Error: cannot implicitly convert expression (t) of type Tuple!string to Tuple!(const(immutable(char)[])) ...\dmd2\src\phobos\std\functional.d(682,14): Error: cannot implicitly convert expression (t) of type Tuple!string to Tuple!(const(immutable(char)[])) test.d(12,19): Error: template instance std.functional.memoize!(len2) error instantiating
Comment #1 by andrej.mitrovich — 2014-04-23T19:39:31Z
This smells like a type-inference compiler bug, *or* a type-inference hash lookup issue. The workaround is simple: https://github.com/D-Programming-Language/phobos/pull/2112
Comment #2 by github-bugzilla — 2014-04-25T19:48:22Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/70dff45550cc97575c24325d6fc0835bc8fa295c Fix Issue 12568 - std.functional.memoize does not work with constant arrays. https://github.com/D-Programming-Language/phobos/commit/68262a48001920538ce78128a2c2245725fb748d Merge pull request #2112 from AndrejMitrovic/Fix12568 Issue 12568 - std.functional.memoize does not work with constant arrays