[Issue 9361] New: Nasty bug and/or error message for template constaints using this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 20 14:19:03 PST 2013


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

           Summary: Nasty bug and/or error message for template constaints
                    using this
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: maidenphil at hotmail.com


--- Comment #0 from Phil Lavoie <maidenphil at hotmail.com> 2013-01-20 14:19:02 PST ---
I tried to make the code as brief as possible:
module rettypeinfer;

import std.stdio;

struct Unit( A ) {

  void useMe() {
    writeln( isUnit!this );
    writeln( is( unitType!this == int ) );
    writeln( ( unitType!this ).stringof );
  }

  void useMoreOfMe( T )( T t ) if( is( atomType!T == unitType!( typeof( this )
) ) ) {
    writeln( "We're ok, but borderline" );
  }

  void butPleaseDontUseMe( T )( T t ) if( is( atomType!T == unitType!( ( this )
) ) ) {
    writeln( "Look at the error message" );
  }

}

template isUnit( alias T ) if( is( T ) ) {
  static if( is( T _: Unit!Args, Args... ) ) {
    enum isUnit = true;
  } else {
    enum isUnit = false;
  }
}
template isUnit( alias T ) if( !is( T ) ) {
  enum isUnit = isUnit!( typeof( T ) );
}
template unitType( alias T ) if( isUnit!T ) {
  static if( is( T _: Unit!Args, Args... ) ) {
    alias unitType = Args[ 0 ];
  } else {
    alias unitType = unitType!( typeof( T ) );
  }
}

struct Atom( A ) {

}

template isAtom( alias A ) if( is( A ) ) {
  static if( is( A _: Atom!Args, Args... ) ) {
    enum isAtom = true;
  } else {
    enum isAtom = false;
  }
}
template isAtom( alias A ) if( !is( A ) ) {
  enum isAtom = isAtom!( typeof( A ) );
}
template atomType( alias T ) if( isAtom!T ) {
  static if( is( T _: Atom!Args, Args... ) ) {
    alias atomType = Args[ 0 ];
  } else {
    alias atomType = atomType!( typeof( T ) );
  }
}

void main( string[] args ) {
  Unit!int u;

  assert( isUnit!u );
  assert( isUnit!( typeof( u ) ) );
  assert( is( unitType!u == int ) );
  assert( is( unitType!( typeof( u ) ) == int ) );

  u.useMe();

  Atom!int a;

  assert( isAtom!a );
  assert( isAtom!( typeof( a ) ) );
  assert( is( atomType!a == int ) );
  assert( is( atomType!( typeof( a ) ) == int ) );

  u.useMoreOfMe( a );

  //Crashes, with nasty error message.
  u.butPleaseDontUseMe( a );
}

Run this and it outputs:
Assertion failure: 'fd && fd->inferRetType' on line 81 in file 'mangle.c'

abnormal program termination

The last function crashes the program. If you replace unitType!this with
unitType( typeof( this ) ) the function works properly, as in the previous
member declaration.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list