summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Directed/nullabletypes/constructor.cs
blob: a9ab5267b642cd7740991ba96486955f14910cde (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
//<Title>Nullable types have a default single-parameter constructor</Title>
//<Description>
// A nullable type can be created with a single argument constructor
// The HasValue property will be set to true, and the Value property will get the value of the constructor
//</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.HasValue);
        Test.Eval(i.Value, 1);
        Test.Eval(s.HasValue);
        Test.Eval(s.Value, default(Struct));
        Test.Eval(imps.HasValue);
        Test.Eval(imps.Value, default(ImplStruct));
        Test.Eval(genfoo.HasValue);
        Test.Eval(genfoo.Value, default(OpenGenImplStruct<Foo>));
        Test.Eval(genint.HasValue);
        Test.Eval(genint.Value, default(CloseGenImplStruct));
    }
}

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