提交 039f7041 编写于 作者: E Evan Hauck 提交者: Jared Parsons

Go through all prototype comments and clean resolved ones.

上级 07ae3f88
......@@ -5427,11 +5427,6 @@ private static void CopyExtensionMethodArguments(AnalyzedArguments originalArgum
Debug.Assert(lookupResult.IsMultiViable);
Debug.Assert(lookupResult.Symbols.Any());
// PROTOTYPE: Include the below code?
//HashSet<DiagnosticInfo> useSiteDiagnostics = null;
//OverloadResolution.BestExtensionOverloadResolution(lookupResult.Symbols, ref useSiteDiagnostics);
//diagnostics.Add(node, useSiteDiagnostics);
var members = ArrayBuilder<Symbol>.GetInstance();
BoundExpression result;
bool wasError;
......@@ -5559,7 +5554,7 @@ private static void CopyExtensionMethodArguments(AnalyzedArguments originalArgum
{
for (int i = methodGroup.Methods.Count - 1; i >= 0; i--)
{
// PROTOTYPE: I think this (the extension class) is wrong. For example, type constraints might not match on the receiver.
// PROTOTYPE: This (the extension class) is wrong. Need to check type compatibility, constraints, etc. (which is what Reduce() == null does)
if (methodGroup.Methods[i].IsInExtensionClass) continue;
if ((object)methodGroup.Methods[i].ReduceExtensionMethod(left.Type) == null) methodGroup.Methods.RemoveAt(i);
}
......
......@@ -888,13 +888,8 @@ private static void CheckRestrictedTypeReceiver(BoundExpression expression, Comp
// Method resolution should never return method kind of UnreducedExtension
Debug.Assert(method.MethodKind != MethodKind.UnreducedExtension);
// Skip building up a new array if the first argument doesn't have to be modified.
// PROTOTYPE: Deal with the comment and commented-out code.
// Because the receiver didn't pass through CoerceArguments, we need to apply an appropriate
// conversion here.
//Debug.Assert(method.ParameterCount > 0);
//Debug.Assert(argsToParams.IsDefault || argsToParams[0] == 0);
//BoundExpression convertedReceiver = CreateConversion(receiver, methodResult.Result.ConversionForArg(0), method.Parameters[0].Type, diagnostics);
// PROTOTYPE: Ensure that the receiver is converted appropriately to the method's receiver type, especially for extension methods.
// Might need to call CreateConversion(receiver, conversionForReceiver, targetType, diagnostics).
var args = analyzedArguments.Arguments.ToImmutable();
// This will be the receiver of the BoundCall node that we create.
......
......@@ -737,27 +737,6 @@ internal virtual bool SupportsExtensionMembers
if (!result.IsMultiViable && (options & LookupOptions.IncludeExtensionMethods) != 0)
{
originalBinder.LookupExtensionMembers(result, name, arity, options, ref useSiteDiagnostics);
// PROTOTYPE: Deal with commented out code here
/*
var tempResult = LookupResult.GetInstance();
originalBinder.LookupExtensionMembers(tempResult, name, arity, options, ref useSiteDiagnostics);
// PROTOTYPE: Provide better errors on lookup failure?
// PROTOTYPE: Extension methods found through member lookup go through this trimming twice (one here, one in overload resolution). Fix?
if (tempResult.IsMultiViable)
{
foreach (var extension in tempResult.Symbols)
{
var method = extension as MethodSymbol;
var receiverType = ((object)method != null && method.MethodKind == MethodKind.ReducedExtension) ? method.ReceiverType : extension.ContainingType.ExtensionClassType;
var conversion = Conversions.ClassifyImplicitConversion(type, receiverType, ref useSiteDiagnostics);
if (ConversionsBase.IsValidExtensionMethodThisArgConversion(conversion))
{
result.MergeEqual(new SingleLookupResult(LookupResultKind.Viable, extension, null));
}
}
}
tempResult.Free();
*/
}
visited?.Free();
......
......@@ -275,10 +275,6 @@ private static bool OverloadResolutionResultIsValid<TMember>(ArrayBuilder<Member
return;
}
// Not spec'ed yet: Extension Everything overload resolution based on receiver type
// PROTOTYPE: We might remove the only applicable member, only to be left with no applicable methods left.
//BestExtensionReceiverResolution(results, ref useSiteDiagnostics);
// SPEC: The best method of the set of candidate methods is identified. If a single best method cannot be identified,
// SPEC: the method invocation is ambiguous, and a binding-time error occurs.
......
......@@ -169,7 +169,7 @@ public override BoundNode VisitCall(BoundCall node)
if (invokedAsExtensionMethod)
{
Debug.Assert(method.IsInExtensionClass || method.MethodKind == MethodKind.ReducedExtension);
method = method.UnreduceExtensionMethod(); // PROTOTYPE: Will be renamed eventually, but this method also handles reduced ext methods
method = method.UnreduceExtensionMethod();
}
// We have already lowered each argument, but we may need some additional rewriting for the arguments,
......
......@@ -52,7 +52,6 @@ private BoundExpression VisitPropertyAccess(BoundPropertyAccess node, bool isLef
// This is a property set access. We return a BoundPropertyAccess node here.
// This node will be rewritten with MakePropertyAssignment when rewriting the enclosing BoundAssignmentOperator.
// PROTOTYPE: Handle extension properties
return oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiverOpt, propertySymbol, resultKind, type) :
new BoundPropertyAccess(syntax, rewrittenReceiverOpt, propertySymbol, resultKind, type);
......@@ -68,7 +67,7 @@ private BoundExpression MakePropertyGetAccess(CSharpSyntaxNode syntax, BoundExpr
{
var rewrittenArguments = ImmutableArray<BoundExpression>.Empty;
Debug.Assert(!(property is UnreducedExtensionPropertySymbol));
Debug.Assert(!property.IsUnreducedExtensionMember);
property = property.UnreduceExtensionProperty() ?? property;
var getMethod = property.GetOwnOrInheritedGetMethod();
......
......@@ -11,6 +11,7 @@ namespace Microsoft.CodeAnalysis.CSharp
{
internal partial class SymbolDisplayVisitor
{
// PROTOTYPE: Handle extension class members nicely
private const string IL_KEYWORD_MODOPT = "modopt";
private const string IL_KEYWORD_MODREQ = "modreq";
......
......@@ -670,7 +670,6 @@ public override bool IsExtensionMethod
{
get
{
// PROTOTYPE: Extension class members?
// This is also populated by loading attributes, but
// loading attributes is more expensive, so we should only do it if
// attributes are requested.
......@@ -701,7 +700,6 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
var attributeData = default(ImmutableArray<CSharpAttributeData>);
var containingPEModuleSymbol = _containingType.ContainingPEModule;
// PROTOTYPE: Extension class members
// Could this possibly be an extension method?
bool alreadySet = _packedFlags.IsExtensionMethodIsPopulated;
bool checkForExtension = alreadySet
......
......@@ -421,7 +421,6 @@ public ImmutableArray<Symbol> GetUnderlyingMembers()
internal void GetExtensionMembers(ArrayBuilder<Symbol> members, string nameOpt, int arity, LookupOptions options)
{
// PROTOTYPE: Find refs of these two props and make sure both are considered.
if (this.MightContainExtensionMembers)
{
DoGetExtensionMembers(members, nameOpt, arity, options);
......
......@@ -306,7 +306,7 @@ public PropertySymbol ReduceExtensionProperty()
/// </summary>
public PropertySymbol UnreduceExtensionProperty()
{
Debug.Assert(!(this is UnreducedExtensionPropertySymbol));
Debug.Assert(!this.IsUnreducedExtensionMember);
if (!this.IsInExtensionClass)
return null;
......
......@@ -1308,11 +1308,6 @@ private MembersAndInitializers GetMembersAndInitializers()
var memberNames = ArrayBuilder<string>.GetInstance(membersDictionary.Count);
memberNames.AddRange(membersDictionary.Keys);
MergePartialMembers(memberNames, membersDictionary, diagnostics);
if (this.IsExtensionClass)
{
// PROTOTYPE: Is this needed?
//ReplaceExtensionClassMembers(memberNames, membersDictionary, diagnostics);
}
memberNames.Free();
AddDeclarationDiagnostics(diagnostics);
state.NotePartComplete(CompletionPart.Members);
......
......@@ -179,8 +179,6 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
var parameter0Type = this.Parameters[0].Type;
if (this.IsInExtensionClass)
{
// PROTOTYPE: figure out what the priority of this error is relative to the others in this if-else chain
// (only one diagnostic is reported, so figure out what's most important - or maybe report multiple)
diagnostics.Add(ErrorCode.ERR_ExtensionMethodInExtensionClass, location);
}
else if (!parameter0Type.IsValidExtensionParameterType())
......
......@@ -382,7 +382,6 @@ public override bool IsExtensionMethod
{
get
{
// PROTOTYPE: Should this include IsInExtensionClass?
return this.flags.IsExtensionMethod;
}
}
......
......@@ -1130,8 +1130,6 @@ public override Symbol GetUnderlyingMember(Symbol symbol)
switch (symbol.Kind)
{
case SymbolKind.Property:
// PROTOTYPE: this is weird.
result = symbol;
{
var property = (PropertySymbol)symbol;
if (property.IsStatic)
......@@ -1158,7 +1156,8 @@ public override Symbol GetUnderlyingMember(Symbol symbol)
}
else
{
result = UnreducedExtensionMethodSymbol.Create(method);
var constructedFrom = method.ConstructedFrom;
result = new UnreducedExtensionMethodSymbol(constructedFrom);
}
// PROTOTYPE: Generics/construction of result? (probably put in Create method)
break;
......
......@@ -146,6 +146,7 @@ public sealed override MethodSymbol OriginalDefinition
}
}
// PROTOTYPE: The only usage of this property is in tests. Is it needed?
internal sealed override MethodSymbol CallsiteReducedFromMethod
{
get
......@@ -155,21 +156,6 @@ internal sealed override MethodSymbol CallsiteReducedFromMethod
}
}
public override TypeSymbol ReceiverType
{
get
{
// PROTOTYPE: Figure this out? What is CallsiteReducedFromMethod (this is only non-test usage)
var reduced = this.CallsiteReducedFromMethod;
if ((object)reduced == null)
{
return this.ContainingType;
}
return reduced.Parameters[0].Type;
}
}
public override TypeSymbol GetTypeInferredDuringReduction(TypeParameterSymbol reducedFromTypeParameter)
{
// This will throw if API shouldn't be supported or there is a problem with the argument.
......
......@@ -414,13 +414,14 @@ public bool IsUnreducedExtensionMember
switch (this.Kind)
{
case SymbolKind.Method:
switch (((MethodSymbol)this).MethodKind)
var method = (MethodSymbol)this;
switch (method.MethodKind)
{
case MethodKind.UnreducedExtension:
return true;
default:
// PROTOTYPE: Do methods with `this` parameter count? (the unreduced form)
return false;
// PROTOTYPE: PE extension class symbols are unreduced, once those are implemented.
return method.IsStatic && method.IsExtensionMethod;
}
case SymbolKind.Property:
return this is UnreducedExtensionPropertySymbol;
......
......@@ -338,7 +338,6 @@ internal static ImmutableArray<TypeSymbol> ToTypes(this ImmutableArray<TypeWithM
/// </summary>
public static MethodSymbol GetConstructedUnreducedFrom(this MethodSymbol method)
{
// PROTOTYPE: Finish this method?
if (method.MethodKind != MethodKind.UnreducedExtension)
{
// not a unreduced extension method
......
......@@ -25,71 +25,15 @@ internal sealed class UnreducedExtensionMethodSymbol : MethodSymbol
private readonly ImmutableArray<TypeSymbol> _typeArguments;
private ImmutableArray<ParameterSymbol> _lazyParameters;
/// <summary>
/// Return the extension method in unreduced form if the extension method
/// is applicable, and satisfies type parameter constraints, based on the
/// "this" argument type. Otherwise, returns null.
/// </summary>
public static MethodSymbol Create(MethodSymbol method, TypeSymbol receiverType, Compilation compilation)
{
Debug.Assert(method.IsInExtensionClass && method.MethodKind != MethodKind.UnreducedExtension);
Debug.Assert((object)receiverType != null);
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
// PROTOTYPE: fix this, left over from ReducedExtensionMethodSymbol
method = method.InferExtensionMethodTypeArguments(receiverType, compilation, ref useSiteDiagnostics);
if ((object)method == null)
{
return null;
}
var conversions = new TypeConversions(method.ContainingAssembly.CorLibrary);
var conversion = conversions.ConvertExtensionMethodThisArg(method.Parameters[0].Type, receiverType, ref useSiteDiagnostics);
if (!conversion.Exists)
{
return null;
}
if (useSiteDiagnostics != null)
{
foreach (var diag in useSiteDiagnostics)
{
if (diag.Severity == DiagnosticSeverity.Error)
{
return null;
}
}
}
return Create(method);
}
public static MethodSymbol Create(MethodSymbol method)
{
Debug.Assert(method.IsInExtensionClass && method.MethodKind != MethodKind.UnreducedExtension);
// The unreduced form is always created from the unconstructed method symbol.
var constructedFrom = method.ConstructedFrom;
var unreducedMethod = new UnreducedExtensionMethodSymbol(constructedFrom);
if (constructedFrom == method)
{
return unreducedMethod;
}
// If the given method is a constructed method, the same type arguments
// are applied to construct the result from the unreduced form.
Debug.Assert(!method.TypeArguments.IsEmpty);
return unreducedMethod.Construct(method.TypeArguments);
}
private UnreducedExtensionMethodSymbol(MethodSymbol unreducedFrom)
public UnreducedExtensionMethodSymbol(MethodSymbol unreducedFrom)
{
Debug.Assert((object)unreducedFrom != null);
Debug.Assert(unreducedFrom.IsInExtensionClass);
// Should never try to unreduce a reduced symbol - callers of this should have short-circuited.
Debug.Assert((object)unreducedFrom.ReducedFrom == null);
Debug.Assert((object)unreducedFrom.UnreducedFrom == null);
Debug.Assert(unreducedFrom.ConstructedFrom == unreducedFrom);
Debug.Assert(unreducedFrom.MethodKind != MethodKind.UnreducedExtension);
_unreducedFrom = unreducedFrom;
_typeMap = TypeMap.Empty.WithAlphaRename(unreducedFrom, this, out _typeParameters);
......@@ -103,9 +47,6 @@ internal override bool TryGetThisParameter(out ParameterSymbol thisParameter)
return true;
}
// PROTOTYPE: Do we need to return something from here? (return null is same as base virtual property)
internal override MethodSymbol CallsiteReducedFromMethod => null;
public override TypeSymbol ReceiverType => null;
internal override TypeSymbol GetTypeInferredDuringUnreduction(TypeParameterSymbol unreducedFromTypeParameter)
......@@ -123,9 +64,6 @@ internal override TypeSymbol GetTypeInferredDuringUnreduction(TypeParameterSymbo
return null;
}
// PROTOTYPE: Same comment as CallsiteReducedFromMethod
public override MethodSymbol ReducedFrom => null;
public override MethodSymbol UnreducedFrom => _unreducedFrom;
public override MethodSymbol ConstructedFrom
......@@ -247,7 +185,6 @@ public override ImmutableArray<ParameterSymbol> Parameters
}
}
// PROTOTYPE: Not here, but need to test explicit interface impls in extension class (should produce error)
internal override bool IsExplicitInterfaceImplementation => false;
public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations => ImmutableArray<MethodSymbol>.Empty;
......
......@@ -27,12 +27,13 @@ public UnreducedExtensionPropertySymbol(PropertySymbol unreducedFrom)
{
Debug.Assert((object)unreducedFrom != null);
Debug.Assert(unreducedFrom.IsInExtensionClass);
Debug.Assert(!(unreducedFrom is UnreducedExtensionPropertySymbol));
Debug.Assert(!unreducedFrom.IsUnreducedExtensionMember);
_unreducedFrom = unreducedFrom;
}
// PROTOTYPE: Make virtual?
// Only use of this is when we know we have an unreduced property and want to "reduce" it
// - no need for it to be on PropertySymbol and be virtual
public PropertySymbol UnreducedFrom => _unreducedFrom;
public override Symbol ContainingSymbol => _unreducedFrom.ContainingSymbol;
......@@ -47,7 +48,6 @@ public UnreducedExtensionPropertySymbol(PropertySymbol unreducedFrom)
public override MethodSymbol SetMethod => _unreducedFrom.SetMethod?.UnreduceExtensionMethod();
// PROTOTYPE: extra parameters causing problems? (find references of IsIndexer)
public override bool IsIndexer => _unreducedFrom.IsIndexer;
public override bool IsAbstract => _unreducedFrom.IsAbstract;
......
......@@ -875,8 +875,17 @@ class BaseClass
extension class ExtClass : BaseClass
{
public int this[int a, int b = 4, params int[] c] =>
Log(a + b + c.Sum(), ""["" + a + b + string.Join("""", c) + ""]"");
public int this[int a, int b = 4, params int[] c]
{
get
{
return Log(a + b + c.Sum(), ""["" + a + b + string.Join("""", c) + ""]"");
}
set
{
Console.Write(""["" + a + b + string.Join("""", c) + ""]="" + value);
}
}
public int Func(int a, int b = 4, params int[] c) =>
Log(a + b + c.Sum(), ""("" + a + b + string.Join("","", c) + "")"");
public static int StaticFunc(int a, int b = 4, params int[] c) =>
......@@ -890,6 +899,7 @@ static void Main()
Console.Write(Log(new BaseClass(), ""1"")[c: new[] { Log(1, ""2""), Log(2, ""3"") }, a: Log(3, ""4"")]);
Console.Write(Log(new BaseClass(), ""1"").Func(c: new[] { Log(1, ""2""), Log(2, ""3"") }, a: Log(3, ""4"")));
Console.Write(BaseClass.StaticFunc(c: new[] { Log(1, ""1""), Log(2, ""2"") }, a: Log(3, ""3"")));
Log(new BaseClass(), ""1"")[c: new[] { Log(1, ""2""), Log(2, ""3"") }, a: Log(3, ""4"")] = 5;
}
}
";
......@@ -897,7 +907,7 @@ static void Main()
CompileAndVerify(
source: text,
additionalRefs: additionalRefs,
expectedOutput: "1234[3412]1234(3412)1234{3412}",
expectedOutput: "1234[3412]1234(3412)1234{3412}1234[3412]=5",
parseOptions: parseOptions);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册