Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Tawfik committed May 31, 2017
1 parent 56764f1 commit 42a8f4c
Show file tree
Hide file tree
Showing 10 changed files with 3,289 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1016,20 +1016,25 @@ internal override DiagnosticInfo GetUseSiteDiagnostic()
}

return CSDiagnosticInfo.IsEmpty(result)
? InterlockedOperations.Initialize(ref _uncommonFields._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
? InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
: result;
}

private DiagnosticInfo InitializeUseSiteDiagnostic(DiagnosticInfo diagnostic)
{
Debug.Assert(!CSDiagnosticInfo.IsEmpty(diagnostic));
if (_packedFlags.IsUseSiteDiagnosticPopulated)
{
return _uncommonFields?._lazyUseSiteDiagnostic;
}

if (diagnostic != null)
{
Debug.Assert(!CSDiagnosticInfo.IsEmpty(diagnostic));
diagnostic = InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, diagnostic, CSDiagnosticInfo.EmptyErrorInfo);
}

_packedFlags.SetIsUseSiteDiagnosticPopulated();
return _uncommonFields?._lazyUseSiteDiagnostic;
return diagnostic;
}

internal override ImmutableArray<string> GetAppliedConditionalSymbols()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal static PEPropertySymbol Create(
var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
Debug.Assert(propertyParams.Length > 0);

var isBad = propEx != null;
var isBad = false;
var returnInfo = propertyParams[0];
PEPropertySymbol result;

Expand All @@ -81,7 +81,7 @@ internal static PEPropertySymbol Create(
result = new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder, out isBad);
}

if (isBad)
if (propEx != null || isBad)
{
result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ internal static void CopyMethodCustomModifiers(
// have already been compared.
MethodSymbol constructedSourceMethod = sourceMethod.ConstructIfGeneric(destinationMethod.TypeArguments);

customModifiers = CustomModifiersTuple.Create(constructedSourceMethod.ReturnTypeCustomModifiers, constructedSourceMethod.RefCustomModifiers);
customModifiers = CustomModifiersTuple.Create(
constructedSourceMethod.ReturnTypeCustomModifiers,
destinationMethod.ReturnsByRef || destinationMethod.ReturnsByRefReadonly ? constructedSourceMethod.RefCustomModifiers : ImmutableArray<CustomModifier>.Empty);

parameters = CopyParameterCustomModifiers(constructedSourceMethod.Parameters, destinationMethod.Parameters, alsoCopyParamsModifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ internal override LexicalSortKey GetLexicalSortKey()

private sealed class InvokeMethod : SourceDelegateMethodSymbol
{
private readonly RefKind refKind;
private readonly RefKind _refKind;
private readonly ImmutableArray<CustomModifier> _refCustomModifiers;

internal InvokeMethod(
SourceMemberContainerTypeSymbol delegateType,
Expand All @@ -242,14 +243,14 @@ internal InvokeMethod(
DiagnosticBag diagnostics)
: base(delegateType, returnType, syntax, MethodKind.DelegateInvoke, DeclarationModifiers.Virtual | DeclarationModifiers.Public)
{
this.refKind = refKind;
this._refKind = refKind;

SyntaxToken arglistToken;
var parameters = ParameterHelpers.MakeParameters(
binder, this, syntax.ParameterList, out arglistToken,
allowRefOrOut: true,
allowThis: false,
addIsConstModifier: false,
addIsConstModifier: true,
diagnostics: diagnostics);

if (arglistToken.Kind() == SyntaxKind.ArgListKeyword)
Expand All @@ -260,6 +261,16 @@ internal InvokeMethod(
diagnostics.Add(ErrorCode.ERR_IllegalVarArgs, new SourceLocation(arglistToken));
}

if (_refKind == RefKind.RefReadOnly)
{
var isConstType = binder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);
_refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(isConstType));
}
else
{
_refCustomModifiers = ImmutableArray<CustomModifier>.Empty;
}

InitializeParameters(parameters);
}

Expand All @@ -270,7 +281,7 @@ public override string Name

internal override RefKind RefKind
{
get { return refKind; }
get { return _refKind; }
}

internal override LexicalSortKey GetLexicalSortKey()
Expand All @@ -288,14 +299,16 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
{
base.AfterAddingTypeMembersChecks(conversions, diagnostics);

if (refKind == RefKind.RefReadOnly)
if (_refKind == RefKind.RefReadOnly)
{
var syntax = (DelegateDeclarationSyntax)SyntaxRef.GetSyntax();
DeclaringCompilation.EnsureIsReadOnlyAttributeExists(diagnostics, syntax.ReturnType.GetLocation(), modifyCompilationForRefReadOnly: true);
}

ParameterHelpers.EnsureIsReadOnlyAttributeExists(Parameters, diagnostics, modifyCompilationForRefReadOnly: true);
}

public override ImmutableArray<CustomModifier> RefCustomModifiers => _refCustomModifiers;
}

private sealed class BeginInvokeMethod : SourceDelegateMethodSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
out _lazyParameters, alsoCopyParamsModifier: true);
}
}
else if (_refKind == RefKind.RefReadOnly && (IsVirtual || IsAbstract))
else if (_refKind == RefKind.RefReadOnly)
{
var isConstType = withTypeParamsBinder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.ReturnType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private SourcePropertySymbol(
_lazyParameters = CustomModifierUtils.CopyParameterCustomModifiers(overriddenOrImplementedProperty.Parameters, _lazyParameters, alsoCopyParamsModifier: isOverride);
}
}
else if (_refKind == RefKind.RefReadOnly && (IsVirtual || IsAbstract))
else if (_refKind == RefKind.RefReadOnly)
{
var isConstType = bodyBinder.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IsConst, diagnostics, syntax.Type);

Expand Down
Loading

0 comments on commit 42a8f4c

Please sign in to comment.