www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error: type XXX is not an expression

reply "Era Scarecrow" <rtcvb32 yahoo.com> writes:
   I feel like i need to fully re-learn and familiarize myself with
D now.

   This is an interesting error I'm coming across, it's not
pointing to anything in particular. I've used the -v verbose flag
and it seems to appear each time after a struct declaration.

code      subrecord
function  smartmerged.subrecord.Changes.__xopEquals
Error: type FlagStates is not an expression
Error: type FlagStates is not an expression

The struct is as follows:

    struct Changes {
      string fileFrom;  ///
      Flags state;      ///previous state, be it master/plugin, or
whatever
      ROMBuffer oldData;///the data in question
    }

aliases referenced from Changes:
    alias immutable(ubyte)[] ROMBuffer;
    alias HandleFlags!(FlagStates, int) Flags;

    enum FlagStates {
      def = 0x0,
      changed   = 1,
      readOnly  = 1 << 1,
      isOriginal= 1 << 2,
      invisible = 1 << 3,
      //other states, truncated for example
    }


    struct HandleFlags(E, I)
      if (is(E == enum) && isIntegral!(I) && isFloatingPoint!(I) ==
false) {
        // Yeah a lot of stuff in here.. binary flag handling
        // in my GitHub somewhere.
    }

   From what I can see, the default opEquals is breaking as it's
doing something. This used to compile and has needed some tweaks.
I'll see if I can compile enough to duplicate this simply.
Sep 01 2013
parent reply "Era Scarecrow" <rtcvb32 yahoo.com> writes:
   k here's the condensed test file. Seems related to an 'alias
this', in theory the HandleFlags bit/flag handling you should be
able to say 'state.def' and it would be the same as
'FlagStates.def' without actually having to name it.

[code]

import std.traits;

///
struct HandleFlags(E, I)
if (is(E == enum) && isIntegral!(I) && isFloatingPoint!(I) ==
false) {
    I state;	///Holds state.
    alias E Enum;
    alias Enum this;    //seems to be root cause of the problem...
}

enum FlagStates {def}

struct Changes {
    string fileFrom;    //goes away if commented out...?
    HandleFlags!(FlagStates, int) state;
}

[/code]
Sep 01 2013
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Sep 02, 2013 at 06:21:18AM +0200, Era Scarecrow wrote:
   k here's the condensed test file. Seems related to an 'alias
 this', in theory the HandleFlags bit/flag handling you should be
 able to say 'state.def' and it would be the same as
 'FlagStates.def' without actually having to name it.
 
 [code]
 
 import std.traits;
 
 ///
 struct HandleFlags(E, I)
 if (is(E == enum) && isIntegral!(I) && isFloatingPoint!(I) ==
 false) {
    I state;	///Holds state.
    alias E Enum;
    alias Enum this;    //seems to be root cause of the problem...
You can't alias a type to this. You need to instantiate it first, then alias the instance to this (because 'this' is an object, not a type). For example: struct S {} struct T { //alias S this; // NG: S is a type S s; alias s this; // OK: s is an instance of S } T -- Three out of two people have difficulties with fractions. -- Dirk Eddelbuettel
Sep 01 2013
parent "Era Scarecrow" <rtcvb32 yahoo.com> writes:
On Monday, 2 September 2013 at 04:49:46 UTC, H. S. Teoh wrote:
 You can't alias a type to this. You need to instantiate it 
 first, then alias the instance to this (because 'this' is an 
 object, not a type). For example:

 	struct S {}
 	struct T {
 		//alias S this;  // NG: S is a type
 		S s;
 		alias s this;	// OK: s is an instance of S
 	}
Curiously the earlier version (v2.60?) Allowed this, but it was an Enum (not a struct) that was being aliased. If memory serves me right, you can alias a function as 'this' as well. (Dern I'm tripping the spam filter.... a lot...)
Sep 01 2013