Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract method refactoring exception after copy-paste local method into for-loop body #17972

Closed
Esidar opened this issue Mar 19, 2017 · 4 comments
Assignees
Labels
Area-IDE Bug Resolution-Duplicate The described behavior is tracked in another issue
Milestone

Comments

@Esidar
Copy link

Esidar commented Mar 19, 2017

Version Used:
VS2017 RTM

My repro steps are rather simple. I just copied local method into a for() loop. Nothing special was about this method (it just borrows some local vars and input arguments from it's parent (int, ref struct, string[]).

System.InvalidOperationException : Unexpected false
   at Roslyn.Utilities.Contract.ThrowIfFalse(Boolean condition,String message)
   at Microsoft.CodeAnalysis.ExtractMethod.ExtractMethodMatrix.GetVariableStyle(Boolean captured,Boolean dataFlowIn,Boolean dataFlowOut,Boolean alwaysAssigned,Boolean variableDeclared,Boolean readInside,Boolean writtenInside,Boolean readOutside,Boolean writtenOutside,Boolean unsafeAddressTaken)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.Analyzer.GetVariableStyle(Dictionary`2 symbolMap,ISymbol symbol,SemanticModel model,ITypeSymbol type,Boolean captured,Boolean dataFlowIn,Boolean dataFlowOut,Boolean alwaysAssigned,Boolean variableDeclared,Boolean readInside,Boolean writtenInside,Boolean readOutside,Boolean writtenOutside,Boolean unsafeAddressTaken)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.Analyzer.GenerateVariableInfoMap(SemanticModel model,DataFlowAnalysis dataFlowAnalysisData,Dictionary`2 symbolMap)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.Analyzer.AnalyzeAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ExtractMethodAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.AbstractExtractMethodService`3.ExtractMethodAsync[TValidator,TExtractor,TResult](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.GetCodeActionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
@CyrusNajmabadi
Copy link
Member

My repro steps are rather simple. I just copied local method into a for() loop

@Esidar Can you provide the actual code you had. We want to ensure that we can actually reproduce what you're hitting.

@Esidar
Copy link
Author

Esidar commented Mar 20, 2017

Unfortunately this code is long gone. Crash was occurring repeatedly few times until I've pressed "Enable and Ignore". It happened after copy pasting a function that was a class member into a for loop so for a moment there were 2 methods with the same name and a delegate using one of those functions. It looked like something this:

for( int i = 0; i < names.Length; i++ )
{
	void OnInsertSelectValue( ref Item hotItem )
	{
		var getVariable = MultiInputMathOperationNode.Create( contextBrowser.mousePosition );
		contextBrowser.AddChild( getVariable );
	}

	var inputSimpleItemAdd = new SimpleItem();
	inputSimpleItemAdd.onSelect = OnInsertSelectValue; // note delegate here
	mathFolder.AddChild( inputSimpleItemAdd );
}
void OnInsertSelectValue( ref Item hotItem )
{
	var getVariable = MultiInputMathOperationNode.Create( contextBrowser.mousePosition );
	contextBrowser.AddChild( getVariable );
}

@Pilchie Pilchie added this to the 15.3 milestone Mar 20, 2017
@Pilchie
Copy link
Member

Pilchie commented Mar 20, 2017

Possible dupe of #17165?

@CyrusNajmabadi
Copy link
Member

Looks like it. Dupe of:#17165

@CyrusNajmabadi CyrusNajmabadi added the Resolution-Duplicate The described behavior is tracked in another issue label Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

3 participants