This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 8263 - op_Explicit in literal conversion
: op_Explicit in literal conversion
Product: Compilers
Classification: Mono
Component: C#
: unspecified
: PC Windows
: --- normal
: ---
Assigned To: Marek Safar
  Show dependency treegraph
Reported: 2012-11-07 11:27 EST by Erik Källén
Modified: 2012-11-11 15:20 EST (History)
2 users (show)

See Also:

Custom mscorlib (108.50 KB, application/x-msdownload)
2012-11-08 09:03 EST, Erik Källén

Description Erik Källén 2012-11-07 11:27:10 EST
I'm using a custom mscorlib which contains (among other things)

struct System.Char {
    public static explicit operator string(char ch) {
        return null;

This means that the following code compiles:

void M() {
    char c = 'c';
    string s = (string)c;

but this code fails to compile:

void M() {
    string s = (string)'c';

MS's compiler does successfully compile the second case.
Comment 1 Erik Källén 2012-11-07 12:39:25 EST
Apparantly I was wrong, the first example does not compile either. Both
examples compiles with MS's compiler.
Comment 2 Erik Källén 2012-11-07 13:00:36 EST
The whole issue seems to be because of a hack in MemberCache.AddMember. I
managed to hack around it in my case, so don't feel obligated to fix the
problem because of me.
Comment 3 Marek Safar 2012-11-08 08:59:22 EST
Could I download your mscorlib from somewhere (or you could attach to the bug
report). It'd help me to reproduce the issue.
Comment 4 Erik Källén 2012-11-08 09:03:14 EST
Created attachment 2884 [details]
Custom mscorlib
Comment 5 Erik Källén 2012-11-08 09:07:21 EST
Btw, the problematic code is at line 300 in membercache.cs, clearly commenting
why it does what it does.
Comment 6 Erik Källén 2012-11-11 09:12:11 EST
I just saw the very hacky solution on github, and I just want to say that you
don't need to do it for me. I have already solved my problem.
Comment 7 Marek Safar 2012-11-11 12:49:31 EST
Fixed in master. The standard is not very clear on char predefined operators. I
decided to allowed them to be compatible with csc.
Comment 8 Erik Källén 2012-11-11 15:20:41 EST
FYI, there also exist other similar issues.


class Delegate {
    public static explicit operator Delegate(MyClass c) { // This operator will
not be used

class string {
    public static explicit operator string(MyClass c) { // This operator will
not be used

Note You need to log in before you can comment on or make changes to this bug.