private void CheckReferenceToVariable(BoundExpression node, Symbol symbol) { Debug.Assert( symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter || symbol is LocalFunctionSymbol ); if ( _staticLocalOrAnonymousFunction is object && Symbol.IsCaptured(symbol, _staticLocalOrAnonymousFunction) ) { var diagnostic = _staticLocalOrAnonymousFunction.MethodKind == MethodKind.LocalFunction ? ErrorCode.ERR_StaticLocalFunctionCannotCaptureVariable : ErrorCode.ERR_StaticAnonymousFunctionCannotCaptureVariable; Error( diagnostic, node, new FormattedSymbol(symbol, SymbolDisplayFormat.ShortFormat) ); } }
private void CheckReferenceToVariable(BoundExpression node, Symbol symbol) { Debug.Assert(symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter || symbol is LocalFunctionSymbol); if (_staticLocalFunction is object && Symbol.IsCaptured(symbol, _staticLocalFunction)) { Error(ErrorCode.ERR_StaticLocalFunctionCannotCaptureVariable, node, new FormattedSymbol(symbol, SymbolDisplayFormat.ShortFormat)); } }
private bool IsCapturedInLocalFunction(int slot) { if (slot <= 0) { return(false); } // Find the root slot, since that would be the only // slot, if any, that is captured in a local function var rootVarInfo = variableBySlot[RootSlot(slot)]; var rootSymbol = rootVarInfo.Symbol; // A variable is captured in a local function iff its // container is higher in the tree than the nearest // local function var nearestLocalFunc = GetNearestLocalFunctionOpt(CurrentSymbol); return(!(nearestLocalFunc is null) && Symbol.IsCaptured(rootSymbol, nearestLocalFunc)); }