D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2355 - is() doesn't resolve aliases before template matching
Summary: is() doesn't resolve aliases before template matching
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
: 5830 6304 (view as issue list)
Depends on:
Blocks:
 
Reported: 2008-09-11 11:46 UTC by Sergey Gromov
Modified: 2011-07-17 17:21 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Sergey Gromov 2008-09-11 11:46:28 UTC
template IsStatic(T : T[S], size_t S) {enum IsStatic = "true: " ~ T.stringof;}
template IsStatic(T) {enum IsStatic = "false";}

template IsStaticSmart(T) {
  static if (is(T E : E[S], size_t S))
    enum IsStaticSmart = "true: " ~ E.stringof;
  else
    enum IsStaticSmart = "false";
}

pragma(msg, IsStatic!(typeof("a")));
pragma(msg, IsStaticSmart!(typeof("a")));

Console output:

>dmd -c test3.d
true: invariant(char)
false
Comment 1 Don 2009-04-08 08:00:35 UTC
Actually, the bug is not really a problem with static arrays. The problem is just that is() isn't resolving aliases. If you replace 'size_t' with 'int' or 'uint', it works fine.
BTW the original code no longer works, since literals are now dynamic arrays, not static arrays.
--------
template IsStaticSmart(T) {
  static if (is( T E : E[S], int S))
    enum IsStaticSmart = "true: " ~ E.stringof;
  else
    enum IsStaticSmart = "false";
}

alias int AliasInt;

template IsStaticSmart2(T) {
  static if (is( T E : E[S], AliasInt S))
    enum IsStaticSmart2 = "true: " ~ E.stringof;
  else
    enum IsStaticSmart2 = "false";
}

char [3] z;

pragma(msg, IsStaticSmart!(typeof(z)));
pragma(msg, IsStaticSmart2!(typeof(z)));

DMD2.028 displays:
true: char
false
Comment 2 yebblies 2011-07-12 01:31:22 UTC
*** Issue 5830 has been marked as a duplicate of this issue. ***
Comment 4 yebblies 2011-07-12 18:25:35 UTC
*** Issue 6304 has been marked as a duplicate of this issue. ***