Bug 8263 - op_Explicit in literal conversion
Summary: op_Explicit in literal conversion
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-11-07 11:27 UTC by Erik Källén
Modified: 2012-11-11 15:20 UTC (History)
2 users (show)

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


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


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:
Status:
RESOLVED FIXED

Description Erik Källén 2012-11-07 11:27:10 UTC
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 UTC
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 UTC
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 UTC
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 UTC
Created attachment 2884 [details]
Custom mscorlib
Comment 5 Erik Källén 2012-11-08 09:07:21 UTC
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 UTC
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 UTC
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 UTC
FYI, there also exist other similar issues.

Eg:

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
    }
}