www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4908] New: Compile-time use of empty() in Tuple failed depending on order of compilation

http://d.puremagic.com/issues/show_bug.cgi?id=4908

           Summary: Compile-time use of empty() in Tuple failed depending
                    on order of compilation
           Product: D
           Version: D2
          Platform: Other
               URL: http://svn.dsource.org/projects/phobos/trunk 2022
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com



---
I have no reduced test case yet.

Unzip the dmd 2.049 release. Add the following lines to std/typecons.d:
--------------------
  struct Tuple(T...)
  {
+     static string test()
+     {
+         enum s = "";
+         return s.empty ? ";" : ";";   // (316)
+     }
+     mixin(test());                    // (318)
  public:
--------------------

Then, compiling certain modules fails depending on the order of compilation:
--------------------
% dmd -c std/string std/concurrency
std/typecons.d(316): Error: cannot evaluate empty("") at compile time
std/typecons.d(318): Error: cannot evaluate test() at compile time
std/typecons.d(318): Error: argument to mixin must be a string, not (test())
% dmd -c std/concurrency std/string
% _
--------------------

The error didn't occur if I modified std.string.indexOf() as follows:
--------------------
  sizediff_t
  indexOf(Char1, Char2)(in Char1[] s, in Char2[] sub,
          CaseSensitive cs = CaseSensitive.yes)
  {
      if (cs == CaseSensitive.yes)
      {
          static if (Char1.sizeof == Char2.sizeof)
          {
-             immutable result = s.length - std.algorithm.find(s, sub).length;
+             immutable result = 0;
              return result == s.length ? -1 : result;
--------------------

This bug is no longer triggered in phobos since changeset 2032.
 http://svn.dsource.org/projects/phobos/trunk 2032

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 21 2010