Thread overview
[Issue 1511] New: static assert doesn't fail as expected
Sep 18, 2007
d-bugmail
Sep 18, 2007
d-bugmail
Sep 18, 2007
d-bugmail
Sep 18, 2007
BCS
Sep 18, 2007
Downs
Sep 18, 2007
d-bugmail
Sep 19, 2007
d-bugmail
[Issue 1511] Expression T[] + T[] passes as having a type
Oct 21, 2007
d-bugmail
September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1511

           Summary: static assert doesn't fail as expected
           Product: D
           Version: 1.014
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: davidl@126.com


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[]);
}


-- 

September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1511





------- Comment #1 from davidl@126.com  2007-09-17 22:09 -------
a simplified case is
void main()
{
    static assert(is(typeof(""+"3")));  // it doesn't fail
}


-- 

September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1511





------- Comment #2 from braddr@puremagic.com  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.


-- 

September 18, 2007
Reply to d-bugmail@puremagic.com,

> http://d.puremagic.com/issues/show_bug.cgi?id=1511
> 
> ------- Comment #2 from braddr@puremagic.com  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[]) ?


September 18, 2007
BCS wrote:
> Reply to d-bugmail@puremagic.com,
> 
>> http://d.puremagic.com/issues/show_bug.cgi?id=1511
>>
>> ------- Comment #2 from braddr@puremagic.com  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.
September 18, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1511





------- Comment #5 from braddr@puremagic.com  2007-09-18 00:32 -------
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.


-- 

September 19, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1511





------- Comment #6 from davidl@126.com  2007-09-18 23:17 -------
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


-- 

October 21, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1511


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Keywords|                            |accepts-invalid
            Summary|static assert doesn't fail  |Expression T[] + T[] passes
                   |as expected                 |as having a type




------- Comment #7 from smjg@iname.com  2007-10-21 15:20 -------
(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.


--