private BoundExpression MakeTupleFieldAccessAndReportUseSiteDiagnostics(BoundExpression tuple, SyntaxNode syntax, FieldSymbol field) { // Use default field rather than implicitly named fields since // fields from inferred names are not usable in C# 7.0. field = field.CorrespondingTupleField ?? field; DiagnosticInfo useSiteInfo = field.GetUseSiteDiagnostic(); if ((object)useSiteInfo != null && useSiteInfo.Severity == DiagnosticSeverity.Error) { Symbol.ReportUseSiteDiagnostic(useSiteInfo, _diagnostics, syntax.Location); } return(MakeTupleFieldAccess(syntax, field, tuple, null, LookupResultKind.Empty)); }
// This returns accessors and may create a temp for the tuple, but will not create temps for the tuple elements. private ImmutableArray <BoundExpression> AccessTupleFields(BoundExpression expression, ArrayBuilder <LocalSymbol> temps, ArrayBuilder <BoundExpression> effects) { Debug.Assert(expression.Type.IsTupleType); var tupleType = expression.Type; var tupleElementTypes = tupleType.TupleElementTypes; var numElements = tupleElementTypes.Length; // save the target as we need to access it multiple times BoundExpression tuple; if (CanChangeValueBetweenReads(expression, localsMayBeAssignedOrCaptured: true)) { BoundAssignmentOperator assignmentToTemp; BoundLocal savedTuple = _factory.StoreToTemp(expression, out assignmentToTemp); effects.Add(assignmentToTemp); temps.Add(savedTuple.LocalSymbol); tuple = savedTuple; } else { tuple = expression; } // list the tuple fields accessors var fields = tupleType.TupleElements; var builder = ArrayBuilder <BoundExpression> .GetInstance(numElements); for (int i = 0; i < numElements; i++) { var field = fields[i]; DiagnosticInfo useSiteInfo = field.GetUseSiteDiagnostic(); if ((object)useSiteInfo != null && useSiteInfo.Severity == DiagnosticSeverity.Error) { Symbol.ReportUseSiteDiagnostic(useSiteInfo, _diagnostics, expression.Syntax.Location); } var fieldAccess = MakeTupleFieldAccess(expression.Syntax, field, tuple, null, LookupResultKind.Empty); builder.Add(fieldAccess); } return(builder.ToImmutableAndFree()); }
private bool TryGetSpecialTypeMember <TSymbol>(CSharpSyntaxNode syntax, SpecialMember specialMember, out TSymbol symbol) where TSymbol : Symbol { symbol = (TSymbol)this.compilation.Assembly.GetSpecialTypeMember(specialMember); if ((object)symbol == null) { MemberDescriptor descriptor = SpecialMembers.GetDescriptor(specialMember); diagnostics.Add(ErrorCode.ERR_MissingPredefinedMember, syntax.Location, descriptor.DeclaringTypeMetadataName, descriptor.Name); return(false); } else { var useSiteDiagnostic = symbol.GetUseSiteDiagnosticForSymbolOrContainingType(); if (useSiteDiagnostic != null) { Symbol.ReportUseSiteDiagnostic(useSiteDiagnostic, diagnostics, new SourceLocation(syntax)); } } return(true); }
protected override bool ReportUseSiteDiagnostic(DiagnosticInfo diagnosticInfo, DiagnosticBag diagnosticBag, Location location) { return(Symbol.ReportUseSiteDiagnostic(diagnosticInfo, diagnosticBag, location)); }