summaryrefslogtreecommitdiff
path: root/tests/src/Loader/classloader/regressions/dev10_568786/4_Misc/ConstrainedMethods.cs
blob: 46fdda235df60c11d1e78c7269fe1e1a5375a087 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// 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;

interface I<S> { string Method(S param); string Method<M>(S param); }

struct MyStruct : I<string>, I<object>
{
    public string Method(string param) { return "string"; }
    public string Method(object param) { return "object"; }
    public string Method<M>(string param) { return "GEN-string"; }
    public string Method<M>(object param) { return "GEN-object"; }
}

class Conversion1<T, U> where U : I<T>, new()
{
    public string Caller1(T param)
    {
        U instance = new U();
        return instance.Method(param);
    }

    public string Caller2(T param)
    {
        U instance = new U();
        return instance.Method<object>(param);
    }
}

class Conversion2<U> where U : I<string>, new()
{
    public string Caller1()
    {
        U instance = new U();
        return instance.Method("mystring");
    }

    public string Caller2()
    {
        U instance = new U();
        return instance.Method<object>("mystring");
    }
}

class Test
{
    static string Caller1<T, U>(T param) where U : I<T>, new()
    {
        U instance = new U();
        return instance.Method(param);
    }

    static string Caller2<T, U>(T param) where U : I<T>, new()
    {
        U instance = new U();
        return instance.Method<object>(param);
    }

    static string Caller3<U>() where U : I<string>, new()
    {
        U instance = new U();
        return instance.Method("mystring");
    }

    static string Caller4<U>() where U : I<string>, new()
    {
        U instance = new U();
        return instance.Method<object>("mystring");
    }

    static int Main()
    {
		int numFailures = 0;
		
        Conversion1<string, MyStruct> c1 = new Conversion1<string, MyStruct>();
        Conversion2<MyStruct> c2 = new Conversion2<MyStruct>();

        string res1 = Caller1<string, MyStruct>("mystring");
        string res2 = Caller2<string, MyStruct>("mystring");
        Console.WriteLine(res1);
        Console.WriteLine(res2);
		if(res1 != "string" && res2 != "GEN-string") numFailures++;



        res1 = Caller3<MyStruct>();
        res2 = Caller4<MyStruct>();
        Console.WriteLine(res1);
        Console.WriteLine(res2);
		if(res1 != "string" && res2 != "GEN-string") numFailures++;



        res1 = c1.Caller1("mystring");
        res2 = c1.Caller2("mystring");
        Console.WriteLine(res1);
        Console.WriteLine(res2);
		if(res1 != "string" && res2 != "GEN-string") numFailures++;

        
        res1 = c2.Caller1();
        res2 = c2.Caller2();
        Console.WriteLine(res1);
        Console.WriteLine(res2);
		if(res1 != "string" && res2 != "GEN-string") numFailures++;

		return ((numFailures == 0)?(100):(-1));
    }
}