summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Directed/nullabletypes/tostring.cs
blob: 21cbf3184d797b67c2c16c56fd56dcc11c966c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//<Title>Nullable types lift the ToString() method from the underlying struct</Title>
//<Description>
//  A nullable type with a value returns the ToString() from the underlying struct
//</Description>

#pragma warning disable 0649

using System;


interface BaseInter { }
interface GenInter<T> { }

struct Struct { }
struct ImplStruct : BaseInter { }
struct OpenGenImplStruct<T> : GenInter<T> { }
struct CloseGenImplStruct : GenInter<int> { }

class Foo { }

class NullableTest1
{
    static int? i = new int?(1);
    static Struct? s = new Struct?(new Struct());
    static ImplStruct? imps = new ImplStruct?(new ImplStruct());
    static OpenGenImplStruct<Foo>? genfoo = new OpenGenImplStruct<Foo>?(new OpenGenImplStruct<Foo>());
    static CloseGenImplStruct? genint = new CloseGenImplStruct?(new CloseGenImplStruct());


    public static void Run()
    {
        Test.Eval(i.ToString(), 1.ToString());
        Test.Eval(s.ToString(), default(Struct).ToString());
        Test.Eval(imps.ToString(), default(ImplStruct).ToString());
        Test.Eval(genfoo.ToString(), default(OpenGenImplStruct<Foo>).ToString());
        Test.Eval(genint.ToString(), default(CloseGenImplStruct).ToString());
    }
}

class NullableTest2
{
    static int? i;
    static Struct? s;
    static ImplStruct? imps;
    static OpenGenImplStruct<Foo>? genfoo;
    static CloseGenImplStruct? genint;


    public static void Run()
    {
        Test.Eval(i.ToString(), "");
        Test.Eval(s.ToString(), "");
        Test.Eval(imps.ToString(), "");
        Test.Eval(genfoo.ToString(), "");
        Test.Eval(genint.ToString(), "");
    }
}

class NullableTests
{
    public static void Run()
    {
        NullableTest1.Run();
        NullableTest2.Run();
    }
}