summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Regression/JitBlue/GitHub_12949/GitHub_12949_6.cs
blob: 1371dbbd47a3c263407d94d63adbc45731acbdad (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.CompilerServices;

public interface IGet 
{
    int Get();
}

public struct R : IGet
{
    public double d;
    public int a;

    public int Get() { return a; }
}

public class X<K> where K: IGet
{
    public X(K r)
    {
        a = new K[2];
        a[0] = r;
    }

    public void Assert(bool b)
    {
        if (!b) throw new Exception("bad!");
    }

    public int Test()
    {
        int r = 0;
        for (int i = 0; i < a.Length; i++)
        {
            Assert(a[i] != null);
            r += a[i].Get();
        }
        return r;
    }

    K[] a;
}

class B
{
    public static int Main()
    {
        var r = new R();
        r.a = 3;
        var a = new X<R>(r);
        int result = a.Test();
        bool passed = result == 3;
        Console.WriteLine("Passed: {0}", passed);
        return passed ? 100 : 0;
    }
}