Bug 34898 - Doesn't compile dynamic on nested templates whereas visual studio does ?
Summary: Doesn't compile dynamic on nested templates whereas visual studio does ?
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2015-10-15 06:03 UTC by smallwill
Modified: 2015-10-20 18:03 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description smallwill 2015-10-15 06:03:56 UTC
I'm using Mono C# compiler version
I first asked about it on stackoverflow http://stackoverflow.com/questions/33144952/in-c-sharp-how-to-dynamically-select-the-type-of-the-generic-function-to-call
Where I learned that it works under visual studio.

In C#, I have some generic function. I have a list of dynamic objects with which I want to call the rightly typed function
It works in simple cases, but doesn't compile as soon as templates are nested.
How to make it work in the nested templates case?

void f1<T>(T a )
  Console.WriteLine( typeof(T) );

void f2<T>(List<T> a )
  Console.WriteLine( typeof(T) );

void f3<T>(List<List<T>> a )
  Console.WriteLine( typeof(T) );

[Test ()]
public void TestDynamic()
  var l = new List<dynamic>();
  //This compiles and works fine 
  foreach (var i in l)
  //prints System.Int32
  //prints System.String

  var l2 = new List<dynamic>();
  l2.Add(new List<int>{3});
  l2.Add(new List<string>{"hello" } );
  //This compiles and works fine
  foreach (var i in l2)
  //prints System.Int32
  //prints System.String

  var l3 = new List<dynamic>();
  l3.Add(new List<List<int>>{new List<int>{3} });
  l3.Add(new List<List<string>> {new List<string>{"hello" } });
  //This doesn't compile : "The type argument for method f3 cannot be inferred from the usage, try specifying the type arguments explicitly
  foreach (var i in l3)
Comment 1 Marek Safar 2015-10-20 18:03:55 UTC
Fixed in master