| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
November 04, 2014 Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
struct Test(T)
{
static if (is(typeof(T) == int))
{
pragma(msg, "test");
this(T t)
{
this.t = t;
}
}
}
void main()
{
//Nothing is printed
Test!int t;
}
Didn't this code used to failed at the point of `typeof(T)`? Has this changed since previous releases?
| ||||
November 04, 2014 Re: Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Meta | On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
> struct Test(T)
> {
> static if (is(typeof(T) == int))
> {
> pragma(msg, "test");
>
> this(T t)
> {
> this.t = t;
> }
> }
> }
>
> void main()
> {
> //Nothing is printed
> Test!int t;
> }
>
> Didn't this code used to failed at the point of `typeof(T)`? Has this changed since previous releases?
It is not static if, it is is. Is is defined as false for invalid types.
| |||
November 04, 2014 Re: Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Tuesday, 4 November 2014 at 09:07:10 UTC, deadalnix wrote:
> It is not static if, it is is. Is is defined as false for invalid types.
Ah, right. That's annoyingly hard to spot, but it is not a bug I suppose.
| |||
November 04, 2014 Re: Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Tuesday, 4 November 2014 at 09:07:10 UTC, deadalnix wrote:
> On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
>> struct Test(T)
>> {
>> static if (is(typeof(T) == int))
>> {
>> pragma(msg, "test");
>>
>> this(T t)
>> {
>> this.t = t;
>> }
>> }
>> }
>>
>> void main()
>> {
>> //Nothing is printed
>> Test!int t;
>> }
>>
>> Didn't this code used to failed at the point of `typeof(T)`? Has this changed since previous releases?
>
> It is not static if, it is is. Is is defined as false for invalid types.
a std.traits.TypeOf that errors out on non-types would be nice.
| |||
November 04, 2014 Re: Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Tuesday, 4 November 2014 at 09:54:44 UTC, John Colvin wrote:
> On Tuesday, 4 November 2014 at 09:07:10 UTC, deadalnix wrote:
>> On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
>>> struct Test(T)
>>> {
>>> static if (is(typeof(T) == int))
>>> {
>>> pragma(msg, "test");
>>>
>>> this(T t)
>>> {
>>> this.t = t;
>>> }
>>> }
>>> }
>>>
>>> void main()
>>> {
>>> //Nothing is printed
>>> Test!int t;
>>> }
>>>
>>> Didn't this code used to failed at the point of `typeof(T)`? Has this changed since previous releases?
>>
>> It is not static if, it is is. Is is defined as false for invalid types.
>
> a std.traits.TypeOf that errors out on non-types would be nice.
woops, ignore me.
| |||
November 04, 2014 Re: Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Meta | On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
> typeof(T)
What is the type of a type?
| |||
November 04, 2014 Re: Is this a bug? `static if` fails silently. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Tuesday, 4 November 2014 at 21:20:59 UTC, Tofu Ninja wrote:
> On Tuesday, 4 November 2014 at 09:00:12 UTC, Meta wrote:
>
>> typeof(T)
>
> What is the type of a type?
A kind, of course. =)
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply