pharo icon indicating copy to clipboard operation
pharo copied to clipboard

Refactoring - Extract Method on a seemingly valid sub expression gives invalid unmatched on string literal error

Open macta opened this issue 1 year ago • 2 comments

Bug description I wanted to extract a portion of a string concatenation sequence, and hiliting what I would consider a valid expression gives the error Invalid source to extract - unmmatched ` in string literal.

To Reproduce Steps to reproduce the behavior:

  1. Create a method like:

	| searchRule replaceRule methodParseTree rewriter |
	
	searchRule := aMethod selector asString, ' arg','
	| `@temps |
	`.@before.	
	', original, '
	`.@after'.
  1. Select the text from aMethod up to the end of arg' (meta -2 selects this as an expression
  2. Select the extract method command
  3. See error

Expected behavior I would expect to be able to extract this as a valid method - I think the error is incorrect.

Screenshots If applicable, add screenshots to help explain your problem.

image

Version information:

  • OS: [e.g. iOS]
  • Version: [e.g. 1.6.1]
  • Pharo Version P12

Expected development cost Medium - needs a bit of understanding of parsing and the refactoring engine

Additional context Add any other context about the problem here.

macta avatar Jun 04 '24 08:06 macta

Splitting the above expression and terminating it with a "." vs a "," correctly lets you extract method - so it looks like this is a question of interpreting the ast.

eg. you can extract the text in this rework (but I still think it should be possible to do my original intent).

searchRule := aMethod selector asString, ' `arg'.
	searchRule := searchRule ,'
	| `@temps |
	`.@before.	
	', original, '
	`.@after'.

macta avatar Jun 04 '24 08:06 macta

In fact looking at the AST it would seem that the refactoring is basing its decision on the wrong node - there is a complete expression that it could use and it must be looking up the wrong one.

image

macta avatar Jun 04 '24 08:06 macta