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

Use fully qualified names when referencing user types. #94267

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public void Emit(SourceProductionContext context)

_writer.WriteLine("""
// <auto-generated/>
#nullable enable
#pragma warning disable CS0612, CS0618 // Suppress warnings about [Obsolete] member usage in generated code.

#nullable enable annotations
#nullable disable warnings

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0612, CS0618
""");

EmitInterceptsLocationAttrDecl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ private TypeSpec CreateEnumerableSpec(TypeParseInfo typeParseInfo)
private ObjectSpec CreateObjectSpec(TypeParseInfo typeParseInfo)
{
INamedTypeSymbol typeSymbol = (INamedTypeSymbol)typeParseInfo.TypeSymbol;
string typeName = typeSymbol.GetTypeName().Name;

ObjectInstantiationStrategy initializationStrategy = ObjectInstantiationStrategy.None;
DiagnosticDescriptor? initDiagDescriptor = null;
Expand Down Expand Up @@ -548,19 +547,19 @@ private ObjectSpec CreateObjectSpec(TypeParseInfo typeParseInfo)
if (!hasPublicParameterlessCtor && hasMultipleParameterizedCtors)
{
initDiagDescriptor = DiagnosticDescriptors.MultipleParameterizedConstructors;
initExceptionMessage = string.Format(Emitter.ExceptionMessages.MultipleParameterizedConstructors, typeName);
initExceptionMessage = string.Format(Emitter.ExceptionMessages.MultipleParameterizedConstructors, typeSymbol.GetFullName());
}

ctor = typeSymbol.IsValueType
// Roslyn ctor fetching APIs include paramerterless ctors for structs, unlike System.Reflection.
// Roslyn ctor fetching APIs include parameterless ctors for structs, unlike System.Reflection.
? parameterizedCtor ?? parameterlessCtor
: parameterlessCtor ?? parameterizedCtor;
}

if (ctor is null)
{
initDiagDescriptor = DiagnosticDescriptors.MissingPublicInstanceConstructor;
initExceptionMessage = string.Format(Emitter.ExceptionMessages.MissingPublicInstanceConstructor, typeName);
initExceptionMessage = string.Format(Emitter.ExceptionMessages.MissingPublicInstanceConstructor, typeSymbol.GetFullName());
}
else
{
Expand Down Expand Up @@ -634,7 +633,7 @@ private ObjectSpec CreateObjectSpec(TypeParseInfo typeParseInfo)

if (invalidParameters?.Count > 0)
{
initExceptionMessage = string.Format(Emitter.ExceptionMessages.CannotBindToConstructorParameter, typeName, FormatParams(invalidParameters));
initExceptionMessage = string.Format(Emitter.ExceptionMessages.CannotBindToConstructorParameter, typeSymbol.GetFullName(), FormatParams(invalidParameters));
}
else if (missingParameters?.Count > 0)
{
Expand All @@ -644,7 +643,7 @@ private ObjectSpec CreateObjectSpec(TypeParseInfo typeParseInfo)
}
else
{
initExceptionMessage = string.Format(Emitter.ExceptionMessages.ConstructorParametersDoNotMatchProperties, typeName, FormatParams(missingParameters));
initExceptionMessage = string.Format(Emitter.ExceptionMessages.ConstructorParametersDoNotMatchProperties, typeSymbol.GetFullName(), FormatParams(missingParameters));
}
}

Expand Down Expand Up @@ -819,7 +818,7 @@ private void RecordTypeDiagnosticIfRequired(TypeParseInfo typeParseInfo, TypeSpe

private void RecordTypeDiagnostic(TypeParseInfo typeParseInfo, DiagnosticDescriptor descriptor)
{
RecordDiagnostic(descriptor, typeParseInfo.BinderInvocation.Location, new object?[] { typeParseInfo.TypeName });
RecordDiagnostic(descriptor, typeParseInfo.BinderInvocation.Location, [typeParseInfo.FullName]);
ReportContainingTypeDiagnosticIfRequired(typeParseInfo);
}

Expand All @@ -829,7 +828,7 @@ private void ReportContainingTypeDiagnosticIfRequired(TypeParseInfo typeParseInf

while (containingTypeDiagInfo is not null)
{
string containingTypeName = containingTypeDiagInfo.TypeName;
string containingTypeName = containingTypeDiagInfo.FullName;

object[] messageArgs = containingTypeDiagInfo.MemberName is string memberName
? new[] { memberName, containingTypeName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void EmitMethods(ImmutableEquatableArray<TypedInterceptorInvocationInfo>? interc
EmitCheckForNullArgument_WithBlankLine(Identifier.configuration, _emitThrowIfNullMethod);
EmitCheckForNullArgument_WithBlankLine(Identifier.instance, _emitThrowIfNullMethod, voidReturn: true);
_writer.WriteLine($$"""
var {{Identifier.typedObj}} = ({{type.DisplayString}}){{Identifier.instance}};
var {{Identifier.typedObj}} = ({{type.TypeRef.FullyQualifiedName}}){{Identifier.instance}};
{{nameof(MethodsToGen_CoreBindingHelper.BindCore)}}({{configExpression}}, ref {{Identifier.typedObj}}, defaultValueIfNotFound: false, {{binderOptionsArg}});
""");
}
Expand Down
Loading