[nem-en] conversion to void operator

Paul Bludov pbludov at gmail.com
Wed Feb 7 06:56:26 CET 2007


The following code:

using System;
using System.Console;

public class Test {
  public static @:> (_ : Test) : int {
    WriteLine("cast to int");
    0
  }
  public static @:> (_ : Test) : void {
    WriteLine("cast to void");
  }
  public SomeMethod() : Test {
    WriteLine("some method");
    null
  }
  public static Main() : void {
    _ = Test().SomeMethod() :> int;
    Test().SomeMethod() :> void;
    _ = ReadLine();
  }
}

Compiles fine and produces output like

some method
cast to int
some method

Where the call to op_Explicit for void type?
Also, implicit conversion to void is not called for

public class Test {
  public static @: (_ : Test) : void {
    WriteLine("implicit cast to void");
  }
  public SomeMethod() : Test {
    WriteLine("some method");
    null
  }
  public static Main() : void {
    Test().SomeMethod(); // Compiler issues a warning here, instead of call 
to op_Implicit : void
    _ = ReadLine();
  }
}

The question is: "Should the compiler do something with the void type 
operators or them must be banned?" 




More information about the devel-en mailing list