digitalmars.D.learn - Weird error when compiling.
- Agustin (30/30) Oct 19 2013 I'm getting Assertion failure: 'thisval && thisval->op ==
 - Agustin (40/70) Oct 19 2013 Sorry i clicked the post button :(. The full code is:
 - TheFlyingFiddle (10/15) Oct 19 2013 typeid(T).toHash can not be evaluated by the compiler at
 - Agustin (3/18) Oct 19 2013 Anyway to evaluate the name of the class and return its hash at
 - TheFlyingFiddle (15/17) Oct 19 2013 I couldn't find the built in hash unction for strings so i used
 - bearophile (40/41) Oct 20 2013 I don't see your error with the following code, please give the
 - Agustin (8/55) Oct 20 2013 TOKclassreference' on line 4067 in file 'interpret.c' when
 - bearophile (5/11) Oct 21 2013 Thank you. I presume this bug is already fixed in the latest
 
I'm getting Assertion failure: 'thisval && thisval->op == 
TOKclassreference' on line 4067 in file 'interpret.c' when 
compiling this.
public class Component {
     ////////////////////////////////////////////////////////////
     /// Component's unique id.
     private hash_t id;
     ....
     ////////////////////////////////////////////////////////////
     /// \brief Default constructor.
     ///
     /// \param[in] id   The id of the component
     ////////////////////////////////////////////////////////////
     public this(hash_t id) {
         this.id = id;
         this.active = true;
         this.validated = true;
     }
}
public class ComponentDetail(T) : Component {
     ////////////////////////////////////////////////////////////
     /// Component's ID as static member.
     public static hash_t ID = typeid(T).toHash;
     ////////////////////////////////////////////////////////////
     /// \brief Default constructor.
     ////////////////////////////////////////////////////////////
     public this() {
         super(ID);
     }
}
 Oct 19 2013
On Sunday, 20 October 2013 at 01:41:58 UTC, Agustin wrote:
 I'm getting Assertion failure: 'thisval && thisval->op == 
 TOKclassreference' on line 4067 in file 'interpret.c' when 
 compiling this.
 public class Component {
     ////////////////////////////////////////////////////////////
     /// Component's unique id.
     private hash_t id;
     ....
     ////////////////////////////////////////////////////////////
     /// \brief Default constructor.
     ///
     /// \param[in] id   The id of the component
     ////////////////////////////////////////////////////////////
     public this(hash_t id) {
         this.id = id;
         this.active = true;
         this.validated = true;
     }
 }
 public class ComponentDetail(T) : Component {
     ////////////////////////////////////////////////////////////
     /// Component's ID as static member.
     public static hash_t ID = typeid(T).toHash;
     ////////////////////////////////////////////////////////////
     /// \brief Default constructor.
     ////////////////////////////////////////////////////////////
     public this() {
         super(ID);
     }
 }
Sorry i clicked the post button :(. The full code is:
I'm getting Assertion failure: 'thisval && thisval->op ==
TOKclassreference' on line 4067 in file 'interpret.c' when
compiling this.
public class Component {
       ////////////////////////////////////////////////////////////
       /// Component's unique id.
       private hash_t id;
       ....
       ////////////////////////////////////////////////////////////
       /// \brief Default constructor.
       ///
       /// \param[in] id   The id of the component
       ////////////////////////////////////////////////////////////
       public this(hash_t id) {
           this.id = id;
           this.active = true;
           this.validated = true;
       }
       ....
}
public class ComponentDetail(T) : Component {
       ////////////////////////////////////////////////////////////
       /// Component's ID as static member.
       public static hash_t ID = typeid(T).toHash;
       ////////////////////////////////////////////////////////////
       /// \brief Default constructor.
       ////////////////////////////////////////////////////////////
       public this() {
           super(ID);
       }
}
private class InputComponent : ComponentDetail!InputComponent {
}
void main() {
       auto pComponent = new InputComponent();
       writeln(pComponent.getId());
       writeln(InputComponent.ID);
}
 Oct 19 2013
 public class ComponentDetail(T) : Component {
       
 ////////////////////////////////////////////////////////////
       /// Component's ID as static member.
       public static hash_t ID = typeid(T).toHash;
typeid(T).toHash can not be evaluated by the compiler at 
compile-time.
Placing the ID initalization in a static this should fix the 
problem.
eg.
public static hash_t ID;
static this()
{
   ID = typeid(T).toHash;
}
 Oct 19 2013
On Sunday, 20 October 2013 at 01:56:39 UTC, TheFlyingFiddle wrote:Anyway to evaluate the name of the class and return its hash at compile time?public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = typeid(T).toHash;typeid(T).toHash can not be evaluated by the compiler at compile-time. Placing the ID initalization in a static this should fix the problem. eg. public static hash_t ID; static this() { ID = typeid(T).toHash; }
 Oct 19 2013
Anyway to evaluate the name of the class and return its hash at compile time?I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; }
 Oct 19 2013
On Sunday, 20 October 2013 at 02:14:55 UTC, TheFlyingFiddle wrote:Works perfectly :), now if i want to implement the same but rather do something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (character[index]) enum GetHash = GetHash(character, hash = (hash * 9) + character[index], ++index); else enum GetHash = hash; } How should i implement it?Anyway to evaluate the name of the class and return its hash at compile time?I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; }
 Oct 20 2013
On Sunday, 20 October 2013 at 21:54:37 UTC, Agustin wrote:On Sunday, 20 October 2013 at 02:14:55 UTC, TheFlyingFiddle wrote:I came up with something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (index < character.length) enum GetHash = GetHash!(character, (hash * 9) + character[index], index + 1); else enum GetHash = hash; }Works perfectly :), now if i want to implement the same but rather do something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (character[index]) enum GetHash = GetHash(character, hash = (hash * 9) + character[index], ++index); else enum GetHash = hash; } How should i implement it?Anyway to evaluate the name of the class and return its hash at compile time?I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; }
 Oct 20 2013
On Sunday, 20 October 2013 at 22:04:49 UTC, Agustin wrote:On Sunday, 20 October 2013 at 21:54:37 UTC, Agustin wrote:And the final template is template Hash(string text, hash_t hash = 0, size_t index = 0) { static if (index < text.length) enum Hash = Hash!(text, (hash ^ text[index]) * 1099511628211UL, index + 1); else enum Hash = hash; } :DOn Sunday, 20 October 2013 at 02:14:55 UTC, TheFlyingFiddle wrote:I came up with something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (index < character.length) enum GetHash = GetHash!(character, (hash * 9) + character[index], index + 1); else enum GetHash = hash; }Works perfectly :), now if i want to implement the same but rather do something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (character[index]) enum GetHash = GetHash(character, hash = (hash * 9) + character[index], ++index); else enum GetHash = hash; } How should i implement it?Anyway to evaluate the name of the class and return its hash at compile time?I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; }
 Oct 20 2013
Agustin:Sorry i clicked the post button :(. The full code is:I don't see your error with the following code, please give the code that gives the error, so we can fix the compiler bug: public class Component { //////////////////////////////////////////////////////////// /// Component's unique id. private hash_t id; .... //////////////////////////////////////////////////////////// /// \brief Default constructor. /// /// \param[in] id The id of the component //////////////////////////////////////////////////////////// public this(hash_t id) { this.id = id; this.active = true; this.validated = true; } .... } public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = typeid(T).toHash; //////////////////////////////////////////////////////////// /// \brief Default constructor. //////////////////////////////////////////////////////////// public this() { super(ID); } } private class InputComponent : ComponentDetail!InputComponent { } void main() { auto pComponent = new InputComponent(); writeln(pComponent.getId()); writeln(InputComponent.ID); } Bye, bearophile
 Oct 20 2013
On Monday, 21 October 2013 at 00:13:59 UTC, bearophile wrote:Agustin:TOKclassreference' on line 4067 in file 'interpret.c' when compiling this.Sorry i clicked the post button :(. The full code is:I don't see your error with the following code, please give the code that gives the error, so we can fix the compiler bug: public class Component { //////////////////////////////////////////////////////////// /// Component's unique id. private hash_t id; ....Assertion failure: 'thisval && thisval->op ==//////////////////////////////////////////////////////////// /// \brief Default constructor. /// /// \param[in] id The id of the component //////////////////////////////////////////////////////////// public this(hash_t id) { this.id = id; this.active = true; this.validated = true; } .... } public class ComponentDetail(T) : Component { //////////////////////////////////////////////////////////// /// Component's ID as static member. public static hash_t ID = typeid(T).toHash; //////////////////////////////////////////////////////////// /// \brief Default constructor. //////////////////////////////////////////////////////////// public this() { super(ID); } } private class InputComponent : ComponentDetail!InputComponent { } void main() { auto pComponent = new InputComponent(); writeln(pComponent.getId()); writeln(InputComponent.ID); } Bye, bearophileThe code is: http://pastebin.com/510YK2Se Using (LDC 0.12.0-beta 1 Ubuntu): http://pastebin.com/2gAWnYyr Using (DMD Windows): Assertion failure: 'thisval && thisval->op == TOKclassreference' on line 4067 in file 'interpret.c' when compiling this.
 Oct 20 2013
Agustin:The code is: http://pastebin.com/510YK2Se Using (LDC 0.12.0-beta 1 Ubuntu): http://pastebin.com/2gAWnYyr Using (DMD Windows): Assertion failure: 'thisval && thisval->op == TOKclassreference' on line 4067 in file 'interpret.c' when compiling this.Thank you. I presume this bug is already fixed in the latest release, dmd V.2.064beta2. Bye, bearophile
 Oct 21 2013








 
 
 
 "Agustin" <agustin.l.alvarez hotmail.com> 