Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Incorrect conversion of classes declared inside of methods. #27

Open
hazzik opened this issue Nov 15, 2013 · 1 comment
Open

Incorrect conversion of classes declared inside of methods. #27

hazzik opened this issue Nov 15, 2013 · 1 comment

Comments

@hazzik
Copy link
Contributor

hazzik commented Nov 15, 2013

public class ContextFactory
{
    private static ContextFactory global = new ContextFactory();

    public interface GlobalSetter {
        public void setContextFactoryGlobal(ContextFactory factory);
        public ContextFactory getContextFactoryGlobal();
    }

    public synchronized static GlobalSetter getGlobalSetter() {
        if (hasCustomGlobal) {
            throw new IllegalStateException();
        }
        hasCustomGlobal = true;
        class GlobalSetterImpl implements GlobalSetter {
            public void setContextFactoryGlobal(ContextFactory factory) {
                global = factory == null ? new ContextFactory() : factory;
            }
            public ContextFactory getContextFactoryGlobal() {
                return global;
            }
        }
        return new GlobalSetterImpl();
    }
}

Is converted to

public class ContextFactory
{
        private static ContextFactory global = new ContextFactory();

    public interface GlobalSetter
    {
        void SetContextFactoryGlobal(ContextFactory factory);

        ContextFactory GetContextFactoryGlobal();
    }

    public static ContextFactory.GlobalSetter GetGlobalSetter()
    {
        lock (typeof(ContextFactory))
        {
            if (hasCustomGlobal)
            {
                throw new InvalidOperationException();
            }
            hasCustomGlobal = true;
            return new _T1664473621(this); // we are in the static method
        }
    }

    internal class _T1664473621 : ContextFactory.GlobalSetter // the name of a class is incorrect
    {
        public virtual void SetContextFactoryGlobal(ContextFactory factory)
        {
            ContextFactory.global = factory == null ? new ContextFactory() : factory;
        }

        public virtual ContextFactory GetContextFactoryGlobal()
        {
            return ContextFactory.global;
        }

        internal _T1664473621(ContextFactory _enclosing)
        {
            this._enclosing = _enclosing;
        }

        private readonly ContextFactory _enclosing;
    }
}
@lilith
Copy link
Contributor

lilith commented May 28, 2015

Could you add a unit test with the expected result, like imazen@b0bc864

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants