Thread overview
[Issue 2848] New: static if (is(type)) + alias fails to compile
Apr 17, 2009
d-bugmail
Apr 17, 2009
d-bugmail
Apr 17, 2009
d-bugmail
Apr 17, 2009
d-bugmail
Jun 22, 2010
Leandro Lucarella
Jun 22, 2010
Don
Jun 22, 2010
Leandro Lucarella
April 17, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2848

           Summary: static if (is(type)) + alias fails to compile
           Product: D
           Version: 1.043
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: llucax@gmail.com


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


-- 

April 17, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2848





------- Comment #1 from llucax@gmail.com  2009-04-17 12:28 -------
BTW, using static if (is(typeof(no_type))) doesn't work either.


-- 

April 17, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2848





------- Comment #2 from llucax@gmail.com  2009-04-17 12:30 -------
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.


-- 

April 17, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2848





------- Comment #3 from fvbommel@wxs.nl  2009-04-17 12:31 -------
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.


-- 

June 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2848



--- Comment #4 from Leandro Lucarella <llucax@gmail.com> 2010-06-21 17:53:23 PDT ---
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 ;).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2848


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug@yahoo.com.au
         Resolution|                            |FIXED


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-06-21 21:04:18 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2848



--- Comment #6 from Leandro Lucarella <llucax@gmail.com> 2010-06-22 06:09:05 PDT ---
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 =)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------