D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2848 - static if (is(type)) + alias fails to compile
Summary: static if (is(type)) + alias fails to compile
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-04-17 12:25 UTC by Leandro Lucarella
Modified: 2014-04-18 09:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Leandro Lucarella 2009-04-17 12:25:46 UTC
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 Leandro Lucarella 2009-04-17 12:28:29 UTC
BTW, using static if (is(typeof(no_type))) doesn't work either.
Comment 2 Leandro Lucarella 2009-04-17 12:30:55 UTC
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 Frits van Bommel 2009-04-17 12:31:09 UTC
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 Leandro Lucarella 2010-06-21 17:53:23 UTC
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 Don 2010-06-21 21:04:18 UTC
(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 Leandro Lucarella 2010-06-22 06:09:05 UTC
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 =)