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
Summary: op_Explicit in literal conversion
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2012-11-07 11:27 UTC by Erik Källén
Modified: 2012-11-11 15:20 UTC (History)
2 users (show)

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

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

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.


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.