Bug 1100 – Alias parameters don't accept primitive types.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-04-06T00:58:37Z
Last change time
2022-12-24T08:20:27Z
Keywords
rejects-valid
Assigned to
Walter Bright
Creator
Reiner Pope
Comments
Comment #0 by reiner.pope — 2007-04-06T00:58:37Z
template MyAlias(alias A)
{
alias A MyAlias;
}
void main()
{
alias MyAlias!(int) Myint; // This line fails:
// template instance MyAlias!(int) does not match any template declaration
}
This disagrees with the spec (http://www.digitalmars.com/d/template.html#aliasparameters) which says that alias parameters can be type names -- I would certainly consider 'int' to be a type name. Furthermore, it's unintuitive because a similar call like this works fine:
struct Int
{
int x;
}
void main()
{
alias MyAlias!(Int) MyInt;
}
Comment #1 by bugzilla — 2007-04-06T02:06:43Z
I changed "type names" to "typedef names" clarify it. The compiler works as intended - use a template type parameter to pass an arbitrary type. "int" is a keyword, not a symbol name.
Comment #2 by reiner.pope — 2007-04-06T02:51:20Z
I would still argue that this is unintuitive behavior; to me an alias parameter is anything that can be aliased. Allowing all types except primitive types in alias parameters creates a seemingly arbitrary distinction between primitive and user types -- don't we want to decrease these differences as much as possible?
I can't think of any realistic use cases for primitive types as alias parameters. However, I also can't for userland types.
PS. To be really pedantic, Int could be regarded as a symbol in the following:
alias int Int;
alias MyAlias!(Int) Int2; // MyAlias from before
// The above alias also doesn't work