Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In C# binder, suggest using UnknownResultType instead of CreateErrorType() #9278

Closed
gafter opened this issue Feb 28, 2016 · 1 comment
Closed
Labels
Area-Compilers Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on.

Comments

@gafter
Copy link
Member

gafter commented Feb 28, 2016

In the C# binders, we currently use CreateErrorType() to create an error type during error recovery. However, we have a cached singleton error type we could use instead called ErrorTypeSymbol.UnknownResultType. Consider refactoring the former to the latter throughout the compiler.

(Thanks to @AlekseyTs for observing this)

@gafter
Copy link
Member Author

gafter commented Feb 28, 2016

The reason not to do this is that UnknownResultType is not merely an error type. Its identity is used throughout the compilers as a flag to indicate that a type stored in an internal variable has not been computed yet. For example

        /// <summary>
        /// For enum types, gets the underlying type. Returns null on all other
        /// kinds of types.
        /// </summary>
        public override NamedTypeSymbol EnumUnderlyingType
        {
            get
            {
                if (ReferenceEquals(_lazyEnumUnderlyingType, ErrorTypeSymbol.UnknownResultType))
                {
                    DiagnosticBag diagnostics = DiagnosticBag.GetInstance();
                    if ((object)Interlocked.CompareExchange(ref _lazyEnumUnderlyingType, this.GetEnumUnderlyingType(diagnostics), ErrorTypeSymbol.UnknownResultType) ==
                        (object)ErrorTypeSymbol.UnknownResultType)
                    {
                        AddDeclarationDiagnostics(diagnostics);
                        this.state.NotePartComplete(CompletionPart.EnumUnderlyingType);
                    }
                    diagnostics.Free();
                }

                return _lazyEnumUnderlyingType;
            }
        }

@gafter gafter closed this as completed Feb 28, 2016
@gafter gafter added the Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on. label Feb 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on.
Projects
None yet
Development

No branches or pull requests

1 participant