import std.stdio;
template k(T)
{
static char[] conceptcheck1(){
T a, b;
static assert(is(typeof(a+b)));
return "";
}
void func(T t)
in
{
static assert(conceptcheck1()=="");
}
body
{
writefln(t);
}
void func1(T t)
in
{
static assert(conceptcheck1()=="");
}
body
{
writefln(t);
}
}
void main()
{
mixin k!(char[]); // this instantiation should make the conceptcheck1 fail
// mixin k!(float);
func("");
// mixin k!(float);
// mixin k!(char[]);
}
Comment #1 by davidl — 2007-09-17T22:09:38Z
a simplified case is
void main()
{
static assert(is(typeof(""+"3"))); // it doesn't fail
}
Comment #2 by braddr — 2007-09-17T23:21:00Z
is(T) is true as long as T is a type. typeof() will return the type of any valid expression. In your examples, all the expressions are valid. So, um.. there's no bug here.
Comment #3 by lovesyao — 2007-09-18T00:00:25Z
Reply to [email protected],
> http://d.puremagic.com/issues/show_bug.cgi?id=1511
>
> ------- Comment #2 from [email protected] 2007-09-17 23:21 -------
> is(T) is true as long as T is a type. typeof() will return the type
> of any
> valid expression. In your examples, all the expressions are valid.
> So, um..
> there's no bug here.
what is (char[] + char[]) ?
Comment #4 by default_357-line — 2007-09-18T00:25:20Z
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
BCS wrote:
> Reply to [email protected],
>
>> http://d.puremagic.com/issues/show_bug.cgi?id=1511
>>
>> ------- Comment #2 from [email protected] 2007-09-17 23:21 -------
>> is(T) is true as long as T is a type. typeof() will return the type
>> of any
>> valid expression. In your examples, all the expressions are valid.
>> So, um..
>> there's no bug here.
>
> what is (char[] + char[]) ?
>
>
char[].
In theory, that's an array operation of addition of chars, but that's
not implemented yet.
It does have a type though.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG72AVpEPJRr05fBERAqJBAJ9cCYVsk/ON2wo70ESoT0rLHxS+igCeNo8+
BiDCgrrRaE7/KuYC00dGlFU=
=PHOR
-----END PGP SIGNATURE-----
Comment #5 by braddr — 2007-09-18T00:32:47Z
Hrm.. this one might need some language lawyering to get an official answer. In my original assessment, I mentally substituted array concatenation when I saw the '+' but that was wrong.
Without the static assert part, which is largely if not completely irrelevant:
typeof("a" + "b") ==> illegal
is(typeof("a" + "b")) ==> 1
So, the question is, should is() actually return true for an illegal typeof()? I suspect a missing layer of semantic analysis, but I'm not sure.
Comment #6 by davidl — 2007-09-18T23:17:40Z
typeof ("a"+"b") is actually evaluated to char[0]
typeof ("a"+"b") f;
static assert(is(f==char[0]); // this passes
but in my opinion, since this operator is not implemented, the compiler should give me fail message
typeof(1~3) b; // this always fails, cause no ~ operator for int, int implemented
Comment #7 by smjg — 2007-10-21T15:20:14Z
(In reply to comment #4)
>> what is (char[] + char[]) ?
>
> char[].
> In theory, that's an array operation of addition of chars, but that's
> not implemented yet.
It isn't not implemented yet, it's not in the language. So the static assert should definitely fail.
Even if it were "not implemented" as part of the compiler being under construction, I wouldn't call this behaviour correct.
The bug also bites for other array types, as long as they're both the same.
Comment #8 by pro.mathias.lang — 2019-05-21T00:44:53Z