Skip to content

Commit

Permalink
Use fully qualified names when referencing user types. (#94267)
Browse files Browse the repository at this point in the history
* Use fully qualified names when referencing user types.

* Use ToUpperInvariant

* Address feedback
  • Loading branch information
eiriktsarpalis authored Nov 2, 2023
1 parent 34bf55c commit b54e9d3
Show file tree
Hide file tree
Showing 62 changed files with 958 additions and 694 deletions.
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

0 comments on commit b54e9d3

Please sign in to comment.