www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7511] New: purity inference does not work for methods of templated aggregates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511

           Summary: purity inference does not work for methods of
                    templated aggregates
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2012-02-15 11:17:33 PST ---
DMD 2.058:

struct S(T){
    T foo(T x){return 2*x;} // this is a pure function for T==int
}
void main()pure{
    S!int s;
    s.foo(2); // error
}

Error: pure function 'main' cannot call impure function 'foo'

The code should compile. (Turtles all the way down: It should work for methods
of nested aggregates of arbitrary nesting level.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 15 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-02-17 07:26:36 PST ---
I think this is an enhancement.

Current attribute inference only works against template function and function
literal, not against normal function.
And non-template function insinde templated aggregate is normal function, so
the inference does not run for them.

But this is a big issue. Almost ranges in std.range should *inherit* original
range's pureness, safety, and nothrow-ness.
To implement it, with current compiler, the only way is to change *all of
member functions* in range structs to be tamplated like follows:

struct Retro(R) {
  R original;

  //auto empty(){ return original.empty; }
  auto empty()(){ return original.empty; }

  //auto front(){ return original.front; }
  auto front()(){ return original.front; }
  ...
}

...but it may introduce mess and dangerous forward reference, IMHO.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511



--- Comment #2 from timon.gehr gmx.ch 2012-02-17 07:46:20 PST ---
Walter stated that this is indeed how it is supposed to work:
http://forum.dlang.org/thread/jhif48$1n0n$1 digitalmars.com?page=3#post-jhjpfp:2419hg:242:40digitalmars.com

If it is an enhancement, then it is a high-priority one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511



--- Comment #3 from timon.gehr gmx.ch 2012-02-25 07:26:51 PST ---
This should probably not be done for virtual template class member functions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-02-18 05:41:38 PST ---
In 2.062, required blocker pull requests were all merged.
Therefore, implementing it was easier than expected.

https://github.com/D-Programming-Language/dmd/pull/1676

(In reply to comment #3)
 This should probably not be done for virtual template class member functions.

I think it should work, at least in following case. https://github.com/D-Programming-Language/dmd/pull/1676/files#L1R76 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 18 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511



--- Comment #5 from github-bugzilla puremagic.com 2013-02-21 22:50:41 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/67fbf5753e9d4a276c354e952ed2f888efcb714c
fix Issue 7511 - attribute inference does not work for methods of templated
aggregates

https://github.com/D-Programming-Language/dmd/commit/20d68fdcb4faad2e522c6d33396f79810626d1f4
Merge pull request #1676 from 9rnsr/fix7511

[enh] Issue 7511 - attribute inference does not work for methods of templated
aggregates

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 12 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7511


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #6 from hsteoh quickfur.ath.cx 2013-08-30 14:04:53 PDT ---
This fix introduced regression issue #10425

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2013