www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4866] New: Static-to-dynamic converted manifest constant array gets non-converted type in static/constraint if

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

           Summary: Static-to-dynamic converted manifest constant array
                    gets non-converted type in static/constraint if
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu gmail.com> 2010-09-14 11:03:49 PDT
---
If a compile-time constant of type T[N] is converted to a manifest constant of
type T[], then the manifest constant gets a wrong type T[N] in static-if or
template constraints.

In the following code, typeof(dynamic) is correct in static-assert, but wrong
in static-if.
-------------------- test1.d
immutable int[3] statik = [ 1, 2, 3 ];
enum immutable(int)[] dynamic = statik;

static assert(is(typeof(dynamic) == immutable(int)[]));
static if (! is(typeof(dynamic) == immutable(int)[]))
{
    static assert(0);   // (7)
}
pragma(msg, "!! ", typeof(dynamic));
--------------------
% dmd -c -o- test1.d
!! immutable(int[3u])
test1.d(7): Error: static assert  (0) is false
--------------------
Note the pragma output.  Its type is the original static one.

The same happens in template constraint:
-------------------- test2.d
void main()
{
    immutable char[3] statik = "abc";
    enum string dynamic = statik;
    foo(dynamic);   // (5)
}
void foo(T)(T a) if (is(typeof(T) == string)) {}
--------------------
% dmd -c -o- test2.d
test2.d(5): Error: template test2.foo(T) if (is(typeof(T) == string)) does not
match any function template declaration
test2.d(5): Error: template test2.foo(T) if (is(typeof(T) == string)) cannot
deduce template function from argument types !()(string)
--------------------

It's ok if a constant is a scalar:
-------------------- test3.d
immutable int original = 10;
enum real converted = original;

static assert(is(typeof(converted) == real));
static if (! is(typeof(converted) == real)) static assert(0);
--------------------
% dmd -c -o- test3.d
% _
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 14 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4866



--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-09-22 10:11:55 PDT
---
Created an attachment (id=763)
Patch against dmd r680, fixes VarDeclaration::semantic()

The problem was that VarDeclaration::semantic() doesn't take it into account
when the variable is a manifest constant or the initializer is non-scalar.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4866


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2010-09-27
21:42:28 PDT ---
http://www.dsource.org/projects/dmd/changeset/697

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