[mini] Runtime check if boxing is needed for DIM constrained calls (mono/mono#15729)
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Thu, 18 Jul 2019 20:46:55 +0000 (16:46 -0400)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2019 20:46:55 +0000 (16:46 -0400)
commitc7f5916ef6458c764b77810419f5788cfebcae4e
treecd02098b613be654472f972688d710cfc3d81d0a
parent614672ca40ab2e02c657dedf0106ab140d6a0d05
[mini] Runtime check if boxing is needed for DIM constrained calls (mono/mono#15729)

This is to handle the following example.  The issue is that in Check() we have
a constrained call where the called method is IAdder`1<!!U>::PlusPlus() which
is a default interface method, and we need to determine at runtime whether to
box the this argument.

```
using System;

public interface IAdder<T> {
int Add (int x);

int PlusPlus () {
return Add (1);
}
}

interface IGen3<T> { }

struct Adder<T> : IAdder<IGen3<T>> {
int _field;
public int Add (int x) {
_field = x + _field;
return _field;
}
}

public class P {
public static int Check<T, U>(T t) where T : IAdder<U> {
return t.PlusPlus () + t.PlusPlus ();
}

public static void Main () {
var x = new Adder<object> ();
int y = Check<Adder<object>, IGen3<object>> (x);
Console.WriteLine ("expect 2, got {0}", y);
}
}
```

Commit migrated from https://github.com/mono/mono/commit/3f55bfb5cc305c1c416edf84fff5440843784deb
src/mono/mono/mini/method-to-ir.c
src/mono/mono/tests/Makefile.am