<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Optional Modifiers and Overload Resolution</title><link>http://blogs.msdn.com/samng/archive/2008/03/05/optional-modifiers-and-overload-resolution.aspx</link><description>Optional Modifiers (or modopts ) are CLR constructs that allow types to be annotated with optional information. This allows compiler writers to annotate their types with additional information that may not have a direct CLR representation. The managed</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Optional Modifiers and Overload Resolution</title><link>http://blogs.msdn.com/samng/archive/2008/03/05/optional-modifiers-and-overload-resolution.aspx#8053042</link><pubDate>Wed, 05 Mar 2008 19:42:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8053042</guid><dc:creator>Thomas Danecker</dc:creator><description>&lt;p&gt;It should be noted that there's also a modreq (required modifier) that &amp;quot;indicates that there is a special semantics to the modified item that should not be ignored, while an optional modifier can simply be ignored.&amp;quot; -- ECMA-335 (CLI), Partition II, 7.1.1&lt;/p&gt;
&lt;p&gt;To the topic:&lt;/p&gt;
&lt;p&gt;I again do not like such kind of overload resolution. Just issue an error and force the user to resolve the ambiguity! Do not even try to resolve it automatically! There is a user compiling the code with whom the compiler can interact. Don't be always so afraid of asking this user what to do if you (the compiler) don't have a clue what he exactly intended to do.&lt;/p&gt;
&lt;p&gt;The problem I'm noticing here is that the programmer currently can only resolve the ambiguity by modifying the called code but not by modifying the calling code. Another possibility is to switch to another language whos compiler is able to select the method intended to call and building a wrapper callable by c#. This of course violates one goal of the CLI - being language-independent, but on the other hand, if using modopt or modreq, it's clear that the produced code isn't intended to be fully language-independent.&lt;/p&gt;
&lt;p&gt;To resolve the issue, Greg Young's suggestion is quite reasonable - if the implementation is embedded in the general handling of types and not only in the heuristic of overload resolution.&lt;/p&gt;
&lt;p&gt;So IMO, the compiler should not silently but noisily pass on modopts. Build clear semantics into the language:&lt;/p&gt;
&lt;p&gt;Types with different or no modopts are assignment compatible.&lt;/p&gt;
&lt;p&gt;Types with different or no modreqs are not.&lt;/p&gt;
&lt;p&gt;Overload resolution should keep its paradigm: Best match. A type with modopts matches better to the equal type with a subset (or none) of these modopts than to the equal type with a different set of modopts. Having only equal types with different sets (or supersets) of modopts available should issue an error.&lt;/p&gt;
&lt;p&gt;So now, the type with the minimal number of modopts won't win until its set of modopts are a subset of the parameter's type's set of modopts.&lt;/p&gt;
&lt;p&gt;Something is still open: How to represent types with modopts in the language?&lt;/p&gt;
&lt;p&gt;.class public auto ansi beforefieldinit Modopt&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; extends [mscorlib]System.Object&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.method public hidebysig instance void&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Foo(int32 x) cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp;} // end of method Modopt::Foo&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.method public hidebysig instance void&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Foo(int32 modopt([mscorlib]IsConst) x) cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp;} // end of method Modopt::Foo&lt;/p&gt;
&lt;p&gt; &amp;nbsp;.method public hidebysig instance int32 modopt([mscorlib]IsConst)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Bar() cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp;} // end of method Modopt::Bar&lt;/p&gt;
&lt;p&gt; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt;} // end of class Modopt&lt;/p&gt;
&lt;p&gt;Now,&lt;/p&gt;
&lt;p&gt;var x = Bar();&lt;/p&gt;
&lt;p&gt;Foo(x);&lt;/p&gt;
&lt;p&gt;would resolve to the second method because the type of x is int32 modopt([mscorlib]IsConst).&lt;/p&gt;
&lt;p&gt;int x = Bar();&lt;/p&gt;
&lt;p&gt;Foo(x);&lt;/p&gt;
&lt;p&gt;would resolve to the first method.&lt;/p&gt;
&lt;p&gt;It would be nice to also be able to specify a type with modopts/modreqs explicitly. Maybe something like the following may fit into the language:&lt;/p&gt;
&lt;p&gt;int modopt(System.Runtime.CompilerServices.IsConst) x = Bar();&lt;/p&gt;
&lt;p&gt;Foo(x);&lt;/p&gt;
&lt;p&gt;That's how I think it should be done. Sorry if I sounded a little bit harsh, but I really love C# and the .net Framework. Hopefully you appreciate my feedback.&lt;/p&gt;
&lt;p&gt;By the way, here's Greg Young's feedback leading to this blog post: &lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=282405"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=282405&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I'll also post this there.&lt;/p&gt;</description></item><item><title>re: Optional Modifiers and Overload Resolution</title><link>http://blogs.msdn.com/samng/archive/2008/03/05/optional-modifiers-and-overload-resolution.aspx#8079483</link><pubDate>Fri, 07 Mar 2008 00:46:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8079483</guid><dc:creator>ildjarn</dc:creator><description>&lt;p&gt;Re: &amp;quot;ie C++ does not allow you to distinguish methods only by their const-ness&amp;quot;, actually VC++ 2008 lets me generate this without much complaint:&lt;/p&gt;
&lt;p&gt;.class public auto ansi beforefieldinit CFoo&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;extends [mscorlib]System.Object&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;.method public hidebysig specialname rtspecialname instance void .ctor(int32 x, int32 y) cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;.field public int32 X&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;.field public int32 Y&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;.class public auto ansi beforefieldinit CBar&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;extends [mscorlib]System.Object&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;.method public hidebysig specialname rtspecialname instance void .ctor() cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;.method public hidebysig instance int32 Foo(class Baz.CFoo foo) cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;.method public hidebysig instance int32 Foo(class Baz.CFoo modopt([mscorlib]System.Runtime.CompilerServices.IsConst) foo) cil managed&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;</description></item><item><title>Community Convergence XLI</title><link>http://blogs.msdn.com/samng/archive/2008/03/05/optional-modifiers-and-overload-resolution.aspx#8160909</link><pubDate>Wed, 12 Mar 2008 00:35:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8160909</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Welcome to the forty-first Community Convergence. The big news this week is that we have moved Future&lt;/p&gt;
</description></item></channel></rss>