提交 c9a10638 编写于 作者: V vladres

* Fix 879811: Do not suppress ambiguity errors if they are caused be the same...

* Fix 879811: Do not suppress ambiguity errors if they are caused be the same nested type imported through several using static directives with different type arguments.
* Fix typos in comments, corrupted characters due to incorrect source encoding, remove unnecessary casts, namespace qualifiers, type arguments and using directives. (changeset 1326357)
上级 98e8c337
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -922,7 +922,7 @@ public ImmutableArray<TypedConstant> VisitArguments(ImmutableArray<BoundExpressi
}
// SPEC: An expression E is an attribute-argument-expression if all of the following statements are true:
// SPEC: 1) The type of E is an attribute parameter type (17.1.3).
// SPEC: 1) The type of E is an attribute parameter type (§17.1.3).
// SPEC: 2) At compile-time, the value of Expression can be resolved to one of the following:
// SPEC: a) A constant value.
// SPEC: b) A System.Type object.
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -2468,9 +2468,9 @@ private ImmutableArray<MethodSymbol> GetCandidatesPassingFinalValidation(CSharpS
// ...
// * If the type parameters of F were substituted in the step above, their constraints are satisfied.
// * If F is a static method, the method group must have resulted from a simple-name, a member-access through a type,
// or a member-access whose receiver can�t be classified as a type or value until after overload resolution (see �7.6.4.1).
// or a member-access whose receiver can't be classified as a type or value until after overload resolution (see §7.6.4.1).
// * If F is an instance method, the method group must have resulted from a simple-name, a member-access through a variable or value,
// or a member-access whose receiver can�t be classified as a type or value until after overload resolution (see �7.6.4.1).
// or a member-access whose receiver can't be classified as a type or value until after overload resolution (see §7.6.4.1).
if (!MemberGroupFinalValidationAccessibilityChecks(methodGroup.ReceiverOpt, result.Member, syntax, candidateDiagnostics, invokedAsExtensionMethod: false) &&
(methodGroup.TypeArgumentsOpt.IsDefault || result.Member.CheckConstraints(this.Conversions, syntax, this.Compilation, candidateDiagnostics)))
......@@ -3452,8 +3452,8 @@ private void BindArrayInitializerExpressions(InitializerExpressionSyntax initial
boundExpression = BadExpression(
expression,
LookupResultKind.Empty,
ImmutableArray.Create<Symbol>(boundExpression.ExpressionSymbol),
ImmutableArray.Create<BoundExpression>(boundExpression));
ImmutableArray.Create(boundExpression.ExpressionSymbol),
ImmutableArray.Create(boundExpression));
}
exprBuilder.Add(boundExpression);
......@@ -4470,7 +4470,7 @@ private BoundExpression BindClassCreationExpression(ObjectCreationExpressionSynt
// SPEC: an expression or an object initializer or collection initializer.
// SPEC: A member initializer that specifies an expression after the equals sign is processed in the same way as an assignment (7.17.1) to the field or property.
// SPEC VIOLATION: Native compiler also allows initialization of fieldlike events in object initializers, so we allow it as well.
// SPEC VIOLATION: Native compiler also allows initialization of field-like events in object initializers, so we allow it as well.
boundMember = BindInstanceMemberAccess(
node: memberName,
......@@ -6108,7 +6108,7 @@ private BoundExpression MakeMemberAccessValue(BoundExpression expr, DiagnosticBa
private void BindMemberAccessReportError(BoundMethodGroup node, DiagnosticBag diagnostics)
{
var nameSyntax = node.NameSyntax;
var syntax = node.MemberAccessExpressionSyntax ?? (CSharpSyntaxNode)nameSyntax;
var syntax = node.MemberAccessExpressionSyntax ?? nameSyntax;
this.BindMemberAccessReportError(syntax, nameSyntax, node.Name, node.ReceiverOpt, node.LookupError, diagnostics);
}
......@@ -6193,7 +6193,7 @@ private bool IsWinRTAsyncInterface(TypeSymbol type)
private BoundExpression BindMemberAccessBadResult(BoundMethodGroup node)
{
var nameSyntax = node.NameSyntax;
var syntax = node.MemberAccessExpressionSyntax ?? (CSharpSyntaxNode)nameSyntax;
var syntax = node.MemberAccessExpressionSyntax ?? nameSyntax;
return this.BindMemberAccessBadResult(syntax, node.Name, node.ReceiverOpt, node.LookupError, StaticCast<Symbol>.From(node.Methods), node.ResultKind);
}
......@@ -6240,7 +6240,7 @@ private BoundExpression BindMemberAccessBadResult(BoundMethodGroup node)
return new BoundBadExpression(
node,
lookupKind,
(object)symbolOpt == null ? ImmutableArray<Symbol>.Empty : ImmutableArray.Create<Symbol>(symbolOpt),
(object)symbolOpt == null ? ImmutableArray<Symbol>.Empty : ImmutableArray.Create(symbolOpt),
boundLeft == null ? ImmutableArray<BoundNode>.Empty : ImmutableArray.Create<BoundNode>(boundLeft),
GetNonMethodMemberType(symbolOpt));
}
......
......@@ -702,7 +702,7 @@ internal virtual bool SupportsExtensionMethods
currentType = currentType.GetNextBaseTypeNoUseSiteDiagnostics(basesBeingResolved, this.Compilation, ref visited);
if ((object)currentType != null)
{
((TypeSymbol)currentType.OriginalDefinition).AddUseSiteDiagnostics(ref useSiteDiagnostics);
currentType.OriginalDefinition.AddUseSiteDiagnostics(ref useSiteDiagnostics);
}
}
......
......@@ -1269,18 +1269,31 @@ public int Compare(Symbol fst, Symbol snd)
if (first.Kind == SymbolKind.NamedType && second.Kind == SymbolKind.NamedType)
{
// ErrorCode.ERR_SameFullNameAggAgg: The type '{1}' exists in both '{0}' and '{2}'
info = new CSDiagnosticInfo(ErrorCode.ERR_SameFullNameAggAgg, originalSymbols,
new object[] { first.ContainingAssembly, first, second.ContainingAssembly });
if (first.OriginalDefinition == second.OriginalDefinition)
{
// We imported different generic instantiations of the same generic type
// and have an ambiguous reference to a type nested in it
reportError = true;
// Do not report this error if the first is declared in source and the second is declared in added module,
// we already reported declaration error about this name collision.
// Do not report this error if both are declared in added modules,
// we will report assembly level declaration error about this name collision.
if (secondBest.IsFromAddedModule)
// '{0}' is an ambiguous reference between '{1}' and '{2}'
info = new CSDiagnosticInfo(ErrorCode.ERR_AmbigContext, originalSymbols,
new object[] { where, first, second });
}
else
{
Debug.Assert(best.IsFromCompilation);
reportError = false;
// ErrorCode.ERR_SameFullNameAggAgg: The type '{1}' exists in both '{0}' and '{2}'
info = new CSDiagnosticInfo(ErrorCode.ERR_SameFullNameAggAgg, originalSymbols,
new object[] { first.ContainingAssembly, first, second.ContainingAssembly });
// Do not report this error if the first is declared in source and the second is declared in added module,
// we already reported declaration error about this name collision.
// Do not report this error if both are declared in added modules,
// we will report assembly level declaration error about this name collision.
if (secondBest.IsFromAddedModule)
{
Debug.Assert(best.IsFromCompilation);
reportError = false;
}
}
}
else if (first.Kind == SymbolKind.Namespace && second.Kind == SymbolKind.NamedType)
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.Serialization;
namespace Microsoft.CodeAnalysis.CSharp
{
......
......@@ -2,10 +2,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.CSharp
{
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.CSharp
{
......
......@@ -3,8 +3,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics;
......
......@@ -3,8 +3,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp
......
......@@ -4,8 +4,6 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using System.Collections.Generic;
......
......@@ -67,7 +67,7 @@ internal ImmutableArray<TypeSymbol> TypeArgumentsWithDefinitionUseSiteDiagnostic
foreach (var typeArgument in result)
{
((TypeSymbol)typeArgument.OriginalDefinition).AddUseSiteDiagnostics(ref useSiteDiagnostics);
typeArgument.OriginalDefinition.AddUseSiteDiagnostics(ref useSiteDiagnostics);
}
return result;
......@@ -76,7 +76,7 @@ internal ImmutableArray<TypeSymbol> TypeArgumentsWithDefinitionUseSiteDiagnostic
internal TypeSymbol TypeArgumentWithDefinitionUseSiteDiagnostics(int index, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
var result = TypeArgumentsNoUseSiteDiagnostics[index];
((TypeSymbol)result.OriginalDefinition).AddUseSiteDiagnostics(ref useSiteDiagnostics);
result.OriginalDefinition.AddUseSiteDiagnostics(ref useSiteDiagnostics);
return result;
}
......@@ -134,7 +134,7 @@ internal bool KnownToHaveNoDeclaredBaseCycles
internal void SetKnownToHaveNoDeclaredBaseCycles()
{
if (!this.hasNoBaseCycles) this.hasNoBaseCycles = true;
this.hasNoBaseCycles = true;
}
/// <summary>
......@@ -569,7 +569,7 @@ public override int GetHashCode()
// ignores custom modifiers.
if (this.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object)
{
return (int)Microsoft.CodeAnalysis.SpecialType.System_Object;
return (int)SpecialType.System_Object;
}
// OriginalDefinition must be object-equivalent.
......@@ -587,7 +587,7 @@ internal override bool Equals(TypeSymbol t2, bool ignoreCustomModifiers = false,
// if ignoring dynamic, then treat dynamic the same as the type 'object'
if (ignoreDynamic &&
t2.TypeKind == TypeKind.DynamicType &&
this.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object)
this.SpecialType == SpecialType.System_Object)
{
return true;
}
......@@ -601,8 +601,8 @@ internal override bool Equals(TypeSymbol t2, bool ignoreCustomModifiers = false,
// CONSIDER: original definitions are not unique for missing metadata type
// symbols. Therefore this code may not behave correctly if 'this' is List<int>
// where List'1 is a missing metadata type symbol, and other is similarly List<int>
// but for a reference-distinct List'1.
// where List`1 is a missing metadata type symbol, and other is similarly List<int>
// but for a reference-distinct List`1.
if (((object)this == (object)thisOriginalDefinition) ||
((object)other == (object)otherOriginalDefinition) ||
(thisOriginalDefinition != otherOriginalDefinition))
......@@ -660,7 +660,6 @@ private bool EqualsComplicatedCases(NamedTypeSymbol other, bool ignoreCustomModi
/// </summary>
/// <param name="typeArguments">The immediate type arguments to be replaced for type
/// parameters in the type.</param>
/// <returns></returns>
public NamedTypeSymbol Construct(params TypeSymbol[] typeArguments)
{
return Construct(typeArguments.AsImmutableOrNull(), false);
......@@ -671,7 +670,6 @@ public NamedTypeSymbol Construct(params TypeSymbol[] typeArguments)
/// </summary>
/// <param name="typeArguments">The immediate type arguments to be replaced for type
/// parameters in the type.</param>
/// <returns></returns>
public NamedTypeSymbol Construct(ImmutableArray<TypeSymbol> typeArguments)
{
return Construct(typeArguments, false);
......@@ -681,7 +679,6 @@ public NamedTypeSymbol Construct(ImmutableArray<TypeSymbol> typeArguments)
/// Returns a constructed type given its type arguments.
/// </summary>
/// <param name="typeArguments"></param>
/// <returns></returns>
public NamedTypeSymbol Construct(IEnumerable<TypeSymbol> typeArguments)
{
return Construct(typeArguments.AsImmutableOrNull(), false);
......@@ -711,7 +708,7 @@ internal NamedTypeSymbol Construct(ImmutableArray<TypeSymbol> arguments, bool un
throw new ArgumentNullException("typeArguments");
}
if (arguments.Any(NamedTypeSymbol.TypeSymbolIsNullFunction))
if (arguments.Any(TypeSymbolIsNullFunction))
{
throw new ArgumentException(CSharpResources.TypeArgumentCannotBeNull, "typeArguments");
}
......@@ -721,7 +718,7 @@ internal NamedTypeSymbol Construct(ImmutableArray<TypeSymbol> arguments, bool un
throw new ArgumentException(CSharpResources.WrongNumberOfTypeArguments, "typeArguments");
}
Debug.Assert(!unbound || arguments.All(NamedTypeSymbol.TypeSymbolIsErrorType));
Debug.Assert(!unbound || arguments.All(TypeSymbolIsErrorType));
if (ConstructedNamedTypeSymbol.TypeParametersMatchTypeArguments(this.TypeParameters, arguments))
{
......@@ -1036,15 +1033,15 @@ protected CharSet DefaultMarshallingCharSet
/// <summary>
/// Declaration security information associated with this type, or null if there is none.
/// </summary>
internal abstract IEnumerable<Microsoft.Cci.SecurityAttribute> GetSecurityInformation();
internal abstract IEnumerable<Cci.SecurityAttribute> GetSecurityInformation();
/// <summary>
/// Returns a sequence of preprocessor symbols specified in <see cref="T:ConditionalAttribute"/> applied on this symbol, or null if there are none.
/// Returns a sequence of preprocessor symbols specified in <see cref="ConditionalAttribute"/> applied on this symbol, or null if there are none.
/// </summary>
internal abstract ImmutableArray<string> GetAppliedConditionalSymbols();
/// <summary>
/// If CoClassAttribute was applied to the type and the attribute argument is a valid named type argument, i.e. accessible class type, then it returns the type symbol for the argument.
/// If <see cref="CoClassAttribute"/> was applied to the type and the attribute argument is a valid named type argument, i.e. accessible class type, then it returns the type symbol for the argument.
/// Otherwise, returns null.
/// </summary>
/// <remarks>
......
......@@ -7,11 +7,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Emit;
using System;
namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
......@@ -880,13 +876,13 @@ private void CheckModifiers(Location location, DiagnosticBag diagnostics)
diagnostics.Add(ErrorCode.ERR_PartialMethodMustReturnVoid, location);
}
else if (IsPartial && !ContainingType.IsInterface && 0 != (DeclarationModifiers &
(CSharp.DeclarationModifiers.AccessibilityMask & ~CSharp.DeclarationModifiers.Private |
CSharp.DeclarationModifiers.Virtual |
CSharp.DeclarationModifiers.Abstract |
CSharp.DeclarationModifiers.Override |
CSharp.DeclarationModifiers.New |
CSharp.DeclarationModifiers.Sealed |
CSharp.DeclarationModifiers.Extern)))
(DeclarationModifiers.AccessibilityMask & ~DeclarationModifiers.Private |
DeclarationModifiers.Virtual |
DeclarationModifiers.Abstract |
DeclarationModifiers.Override |
DeclarationModifiers.New |
DeclarationModifiers.Sealed |
DeclarationModifiers.Extern)))
{
diagnostics.Add(ErrorCode.ERR_PartialMethodInvalidModifier, location);
}
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Text;
......
......@@ -123,7 +123,7 @@ public class A
var compilation1 = CreateCompilationWithMscorlib(source1);
compilation1.VerifyDiagnostics(
// (4,22): error CS0110: The evaluation of the constant value for 'A.x' involves a circular definition
Diagnostic(CSharp.ErrorCode.ERR_CircConstValue, "x").WithArguments("A.x"));
Diagnostic(ErrorCode.ERR_CircConstValue, "x").WithArguments("A.x"));
string source2 = @"
public class B
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -1867,5 +1866,99 @@ static void Main()
Diagnostic(ErrorCode.ERR_NonInvocableMemberCalled, "Assembly").WithArguments("System.Reflection.Assembly").WithLocation(9, 41)
);
}
[Fact]
[WorkItem(879811, "DevDiv")]
public void Bug879811_1()
{
const string source = @"
using Static<string>;
using Static<int>;
public static class Static<T>
{
public class Nested
{
public void M() { }
}
}
class D
{
static void Main(string[] args)
{
var c = new Nested();
c.M();
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (17,21): error CS0104: 'Nested' is an ambiguous reference between 'Static<int>.Nested' and 'Static<string>.Nested'
// var c = new Nested();
Diagnostic(ErrorCode.ERR_AmbigContext, "Nested").WithArguments("Nested", "Static<int>.Nested", "Static<string>.Nested").WithLocation(17, 21));
}
[Fact]
[WorkItem(879811, "DevDiv")]
public void Bug879811_2()
{
const string source = @"
using Static<string>;
using Static<System.String>;
public static class Static<T>
{
public class Nested
{
public void M() { }
}
}
class D
{
static void Main()
{
var c = new Nested();
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (3,7): warning CS0105: The using directive for 'Static<string>' appeared previously in this namespace
// using Static<System.String>;
Diagnostic(ErrorCode.WRN_DuplicateUsing, "Static<System.String>").WithArguments("Static<string>").WithLocation(3, 7),
// (3,1): hidden CS8019: Unnecessary using directive.
// using Static<System.String>;
Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using Static<System.String>;").WithLocation(3, 1));
}
[Fact]
[WorkItem(879811, "DevDiv")]
public void Bug879811_3()
{
const string source = @"
using Static<string>;
public static class Static<T>
{
public class Nested
{
public void M() { }
}
}
namespace N
{
using Static<int>;
class D
{
static void Main()
{
Static<int>.Nested c = new Nested();
}
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (2,1): hidden CS8019: Unnecessary using directive.
// using Static<string>;
Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using Static<string>;").WithLocation(2, 1));
}
}
}
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
......
......@@ -80,7 +80,7 @@ expectedOutput:="123")
<Fact()>
Public Sub Bug707924a()
Dim source = My.Resources.Resource.T_1247520
Dim result = Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(source).ToString()
Dim result = VisualBasicSyntaxTree.ParseText(source).ToString()
Assert.Equal(source, result)
End Sub
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册