You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
First of all, I don't know if this belongs here on in the MonoDevelop bug tracker.
When I was developing LockThisIssue, I encountered a bug that occurred in MonoDevelop when running the issue, but not in the unit tests.
The problem seems to be caused by a combination of script.Remove and script.Link. While this is may be a nonsensical operation, the NRefactory test context does NOT warn against it (no exceptions).
NRefactory seems to just ignore the removed nodes, while MonoDevelop attempts to write text for those nodes.
using ICSharpCode.NRefactory.CSharp.Refactoring;using System.Collections.Generic;using System.Linq;namespace ICSharpCode.NRefactory.CSharp
{[ContextAction("Remove block contents", Description ="Remove block contents to reproduce weird NRefactory inconsistency")]publicclassWeirdAction:ICodeActionProvider{publicIEnumerable<CodeAction>GetActions(RefactoringContextcontext){varnode= context.GetSelectedNodes().FirstOrDefault();varblock= node as BlockStatement;if(block==null){yieldbreak;}yieldreturnnew CodeAction(context.TranslateString("Remove block contents"),script =>{varnewIdentifiers=newList<Identifier>();varidentifiers= block.Descendants.OfType<Identifier>();foreach(var identifier in identifiers){varnewIdentifier= Identifier.Create("replacement"); script.Replace(identifier, newIdentifier); newIdentifiers.Add(newIdentifier);}foreach(var statement in block.Statements.Skip(1)){ script.Remove(statement);} script.Link(newIdentifiers.ToArray());}, block);}}}
Now, this test passes:
varinput=@"class TestClass{ void Foo() { if (true) <-{ int x = 1; int y = 2; }-> }}";varoutput=@"class TestClass{ void Foo() { if (true) { int replacement = 1; } }}";Test<WeirdAction>(input, output);
But if we run this with MonoDevelop, we get this:
I understand that linking and removing the same node is not a good idea and that workarounds are trivial, but still having some sort of exception when running the test cases would be very helpful - because right now actions and issues could pass the tests but still fail in real world usage.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
First of all, I don't know if this belongs here on in the MonoDevelop bug tracker.
When I was developing LockThisIssue, I encountered a bug that occurred in MonoDevelop when running the issue, but not in the unit tests.
The problem seems to be caused by a combination of script.Remove and script.Link. While this is may be a nonsensical operation, the NRefactory test context does NOT warn against it (no exceptions).
NRefactory seems to just ignore the removed nodes, while MonoDevelop attempts to write text for those nodes.
Consider this test case:
Now, apply this action:
This NRefactory test passes:
However, if we run this on MonoDevelop, it will still try to put text inside the block.
Additionally, if there is more than one linked and removed node, MonoDevelop will attempt to put text for each block.
Things get worse when not all fields are removed.
Now, this test passes:
But if we run this with MonoDevelop, we get this:
I understand that linking and removing the same node is not a good idea and that workarounds are trivial, but still having some sort of exception when running the test cases would be very helpful - because right now actions and issues could pass the tests but still fail in real world usage.
The text was updated successfully, but these errors were encountered: