-
Notifications
You must be signed in to change notification settings - Fork 296
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 places new method call in incorrect line position for *some* extracts, causes parser/resolver/logical errors #2284
Comments
I've added some line numbers as comments to help identify the bug. Option Explicit '1
'2
Sub foo() '3
'4
Dim x As String ' 5
x = "foo" ' 6
'7
End Sub '8
'9
Sub bar() '10
'11
End Sub '12 I trigger the Extract Method command by right clicking anywhere in Line Option Explicit '1
'2
Sub foo() '3
'4
'7
NewMethod
End Sub '8
Private Sub NewMethod()
Dim x As String ' 5
x = "foo" ' 6
End Sub
'9
Sub bar() '10
'11
End Sub '12 Note that the call to the new method, above, should be inserted between the lines commented with That can lead to changed execution paths/outcomes, like this, where the refactored code is never executed. Before Option Explicit '1
'2
Sub foo() '3
'4
Dim x As String ' 5
x = "foo" ' 6
Exit Sub ' 7
'8
End Sub '9 After Option Explicit '1
'2
Sub foo() '3
'4
Exit Sub ' 7
NewMethod
'8
End Sub '9
Private Sub NewMethod()
Dim x As String ' 5
x = "foo" ' 6
End Sub |
see #2285 for another example |
This should be simple to fix. The problem is that the "newMethodCall" is inserted at the SelectionStart here var newMethod = constructLinesOfProc(codeModule, model);
codeModule.InsertLines(positionToInsertNewMethod.StartLine, newMethod);
removeSelection(codeModule, selectionToRemove);
codeModule.InsertLines(selection.StartLine, newMethodCall); This needs to be looked at a bit better. It might be possible to just insert one line earlier (but that could be a problem). Alternatively |
Probably the same underlying issue as #2202 |
This is doing the same thing for me. This:
Turns into this:
|
@Falthazar aye, the extract method refactoring, as crucially important as it is, is currently considered broken. I'd recommend avoiding its use for now. I need to make a note to remove it from the refactorings menu for the 2.0.12 release. |
Since the Extract Method refactoring is in dire need of a rewrite from scratch, all [bug] issues pertaining to it, are in the process of becoming irrelevant. Closing. |
Extract Method seems to cause a syntax error when the extracted statements are near the
topbottom of the procedure, and possibly other situations.Before:
After:
The text was updated successfully, but these errors were encountered: