www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10056] New: Strange Error with templates and string.format

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

           Summary: Strange Error with templates and string.format
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: puneet coverify.org


--- Comment #0 from Puneet Goel <puneet coverify.org> 2013-05-10 04:55:53 PDT
---
The following code compiles and runs well with version dmd-2.062.

Now I am compiling the following code with current github/master snapshot:
commit cfb631d40fe708fe04c54402fca8e0a72a2b850f
Merge: 526b57d aa70fab
Author: Martin Nowak <code dawg.eu>
Date:   Fri May 10 01:34:12 2013 -0700

I get an error:
$ rdmd --force foo.d
...... /github-d/bin/../phobos/std/range.d(611): Error: static assert  "Cannot
put a dchar into a Appender!(string)"

I have tried minimizing this strange testcase, but could not go any further.
For example, if I comment out lines 2 to 4, dmd compiles the code without an
issue.


template Foo(T, U, string OP) {              // 1
  static if(T.ISEMPTY && U.ISEMPTY)          // 2
    enum bool S = false;                     // 3
  else                                       // 4
    enum bool S = false;
  alias Foo!(false, false, 0) Foo;
}

struct Foo(bool S, bool L, string VAL) {
  enum bool    ISEMPTY   = S;
}

template Foo(T) {
  alias Foo!(false, false, T.sizeof*8) Foo;
}

template Frop(size_t N) {
  alias Foo!(false, false, N) Frop;
}

struct Foo(bool S, bool L, size_t N) {
  import std.format;
  void bar(ref FormatSpec!char f) {}

  string bar() {
    import std.string;
    format("%b", 0);;
    return "";
  }

  public bool opEquals(T)(T other) {
    alias Foo!(typeof(this), T, "CMP") P;
    return false;
  }
}

void main() {
  alias Frop!1 Zoo;
  enum Zoo ZOO=Zoo.init;
}

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-05-11 06:29:15 PDT ---
This regression is caused by the commit:
https://github.com/D-Programming-Language/dmd/commit/596c1128f4de2b246d339497e1bcec70d93ffd78

Reduced test case:
-------
void main()
{
    alias Zoo = Foo!(false, false, 1);
}

struct Foo(bool S, bool L, size_t N)
{
    string bar()
    {
        Appender!(string) w;
        char[] buf; put(w, buf);
        return "";
    }

    public bool opEquals(T)(T other)
    {
        alias Foo!(typeof(this), T, "CMP") P;
        return false;
    }
}

template Foo(T, U, string OP)
{
    static if (T.ISEMPTY && U.ISEMPTY)
        enum bool S = false;
    else
        enum bool S = false;

    alias Foo = Foo!(false, false, 0);
}

/**********************************************/

void put(R, E)(ref R r, E e)
{
    static if (is(typeof(r.put(e))))
    {
        r.put(e);
    }
    else
    {
        static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof);
    }
}

struct Appender(A : T[], T)
{
    private template canPutItem(U)
    {
        enum bool canPutItem = is(U : T);
    }
    private template canPutRange(R)
    {
        enum bool canPutRange = is(typeof(Appender.init.put(R.init[0])));
    }

    void put(U)(U item) if (canPutItem!U)
    {
        char[T.sizeof == 1 ? 4 : 2] encoded;
        put(encoded[]);
    }
    void put(R)(R items) if (canPutRange!R)
    {
    }
}

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


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

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


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-05-11 08:38:51 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2013

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



--- Comment #3 from github-bugzilla puremagic.com 2013-05-11 15:08:32 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/9577d0770cb3c721e6679267c634a58407ab0e20
fix Issue 10056 - Strange Error with templates and string.format

If IFTI error is gagged (`(flags&1) != 0` in deduceTemplateFunction), function
body semantic should be delayed, as same as `FuncDeclaration::overloadResolve`
do.

For the lazily function semantic, hasIdentity(Assign|Equals) should not
allocate arguments `Expressions` on stack.

https://github.com/D-Programming-Language/dmd/commit/848dabb4680ddee00f69ab6c6b80278ea5d553e7
Merge pull request #2013 from 9rnsr/fix10056

[REG2.063a] Issue 10056 - Strange Error with templates and string.format

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


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