www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1511] New: static assert doesn't fail as expected

reply d-bugmail puremagic.com writes:
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[]);
}


-- 
Sep 17 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1511






a simplified case is
void main()
{
    static assert(is(typeof(""+"3")));  // it doesn't fail 
}


-- 
Sep 17 2007
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1511






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.


-- 
Sep 17 2007
parent reply BCS <ao pathlink.com> writes:
Reply to d-bugmail puremagic.com,

 http://d.puremagic.com/issues/show_bug.cgi?id=1511
 

 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[]) ?
Sep 17 2007
parent Downs <default_357-line yahoo.de> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS wrote:
 Reply to d-bugmail puremagic.com,
 
 http://d.puremagic.com/issues/show_bug.cgi?id=1511


 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-----
Sep 17 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1511






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.


-- 
Sep 17 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1511






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


-- 
Sep 18 2007
prev sibling parent d-bugmail puremagic.com writes:
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






 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. --
Oct 21 2007