using Nemerle.IO; using System.Console; [Record] class Printer[T] { public mutable f : T; public override ToString () : string { typeof (T).ToString () + " : " + f.ToString () } } namespace Bug801 { public class GenericCast[F, T] { private from : F; public this(from : F) { this.from = from } public Run() : T { from :> T } } public class Runner { public static Go() : void { def c = GenericCast(100); try { System.Console.WriteLine (GenericCast (42).Run () : int); _ = c.Run() : byte } catch { | _ is System.InvalidCastException => System.Console.WriteLine ("OK, got InvalidCast"); } } } } namespace BoxField { public class B { public mutable x : int } public class A[T] where T : B, new () { public static f (t : T) : void { def x = t.x; System.Console.WriteLine (x); } public static Run () : void { def t = T (); t.x = 31; f (t) } } } module M { list_of_objects () : void { def print_list (l) { try { WriteLine (l); } catch { | e => WriteLine (e.Message); } } def lx = [0, "1", 2:object]; def ly = [0:object, "1", 2:object]; print_list (lx); print_list (ly); } runner (f : void -> void) : void { f () } xx : long; // W: field `xx' is never assigned to, and will always have its default value apply (x:object,y:object):object { x :> int + y :> int } PassCB (ini : int) : int { def loop (acc, n) { if (n < 0) acc else loop (apply (acc, acc), n - 1) } loop (ini, 5) :> int } Main () : void { mutable x = (42 : object); printf ("%d\n", (x :> int)); x = 6 * 9; printf ("%d\n", (x :> int)); x = "foo"; printf ("%s\n", (x :> string)); mutable y = (420 : object); printf ("%d\n", (y :> int)); def f () { y = 6 * 9 + 1; printf ("%d\n", (y :> int)); y = "bar"; printf ("%s\n", (y :> string)); }; runner (f); def x1 = (1 : object); def tab = array [("ala" : object), "kot", x1]; printf ("%d\n", tab.Length); printf ("%s %s %s\n", 1.GetType ().FullName, 42.ToString (), xx.GetType().Name); def p1 = Printer (42); System.Console.WriteLine (p1); p1.f = 43; System.Console.WriteLine (p1); def p2 = Printer.[object] (42); System.Console.WriteLine (p2); p2.f = 43; System.Console.WriteLine (p2); list_of_objects (); { def f (o : option [object * object]) { System.Console.WriteLine (o); } def g (x : object * object, y : object * object) { System.Console.WriteLine (x); System.Console.WriteLine (y); } g (("foo","bar"),(3,4)); f (Some (1, 2)); } assert (M.PassCB (10) == 640); Bug801.Runner.Go (); BoxField.A.[BoxField.B].Run (); } } /* BEGIN-OUTPUT 42 54 foo 420 55 bar 3 System.Int32 42 Int64 System.Int32 : 42 System.Int32 : 43 System.Object : 42 System.Object : 43 [0, 1, 2] [0, 1, 2] (foo, bar) (3, 4) Some ((1, 2)) 42 OK, got InvalidCast 31 END-OUTPUT */