Bug 2848 – static if (is(type)) + alias fails to compile
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2009-04-17T12:25:00Z
Last change time
2014-04-18T09:12:04Z
Keywords
rejects-valid
Assigned to
nobody
Creator
leandro.lucarella
Comments
Comment #0 by leandro.lucarella — 2009-04-17T12:25:46Z
This simple test fails to compile:
static if (!is(typeof(no_type)))
alias char[] no_type;
no_type x;
In all D compilers available, tested in GDC, DMD 1.043, DMD 2.027 and LDC r1197 (so it seems like a front-end issue).
The error is:
t.d:3: Error: identifier 'no_type' is not defined
t.d:3: Error: no_type is used as a type
t.d:3: variable t.x voids have no value
This test doesn't compile either:
static if (!is(typeof(no_type))) {
alias char[] no_type;
no_type y;
}
Error:
t.d(3): Error: identifier 'no_type' is not defined
t.d(3): Error: no_type is used as a type
t.d(3): variable t.x voids have no value
Comment #1 by leandro.lucarella — 2009-04-17T12:28:29Z
BTW, using static if (is(typeof(no_type))) doesn't work either.
Comment #2 by leandro.lucarella — 2009-04-17T12:30:55Z
It seems to happen for array, int and float aliasee, but not for Object or struct types...
This workaround works:
alias char[] String;
static if (!is(no_type)) {
alias String no_type;
no_type y;
}
no_type x;
It seems not to fail when aliassed to user-defined types (classes, structs, enums, aliases, typedefs), but for primitive types and arrays it fails.
typedef have the same problem.
Comment #3 by fvbommel — 2009-04-17T12:31:09Z
Workaround:
----
alias char[] String;
static if (!is(no_type))
alias String no_type;
no_type x;
----
It seems to fail when the aliased type is a primitive type or array (static, dynamic or associative).
It doesn't fail if it's a class, struct, enum, typedef or aliased type.
Comment #4 by leandro.lucarella — 2010-06-21T17:53:23Z
Works in DMD 1.062, I don't know when it got fixed. I guess it will work in DMD 2.0xx, but I don't have one installed to test.
If somebody wants to try it, this bug can be closed (maybe Don who seems to bisect a lot and has an environment to do that easily wants to bisect DMD to see when it got fixed and add the proper changelog entry ;).
Comment #5 by clugdbug — 2010-06-21T21:04:18Z
(In reply to comment #4)
> Works in DMD 1.062, I don't know when it got fixed. I guess it will work in DMD
> 2.0xx, but I don't have one installed to test.
>
> If somebody wants to try it, this bug can be closed (maybe Don who seems to
> bisect a lot and has an environment to do that easily wants to bisect DMD to
> see when it got fixed and add the proper changelog entry ;).
No probs.
Fixed DMD 1.050.
Comment #6 by leandro.lucarella — 2010-06-22T06:09:05Z
Thanks!(In reply to comment #5)
> (In reply to comment #4)
> > Works in DMD 1.062, I don't know when it got fixed. I guess it will work in DMD
> > 2.0xx, but I don't have one installed to test.
> >
> > If somebody wants to try it, this bug can be closed (maybe Don who seems to
> > bisect a lot and has an environment to do that easily wants to bisect DMD to
> > see when it got fixed and add the proper changelog entry ;).
> No probs.
> Fixed DMD 1.050.
Thanks =)