[Issue 4866] New: Static-to-dynamic converted manifest constant array gets non-converted type in static/constraint if
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 14 11:04:19 PDT 2010
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 at puremagic.com
ReportedBy: rsinfu at gmail.com
--- Comment #0 from Shin Fujishiro <rsinfu at 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: -------
More information about the Digitalmars-d-bugs
mailing list