8

Here you can see how ReSharper is suggesting a change

enter image description here

Now here you can see how Resharper is changing up the code but the result is not correct because it is newing up a class, assigning a value to a property on it and then returning a totally new instance of that class that doesn't have the value assigned to it.

enter image description here

I had cursor on the new keyword. Pressed Alt+Enter and chose the option called "use object initializer".

Is this a possible bug in ReSharper or am I just missing something here?

AvetisCodes
  • 1,375
  • 2
  • 11
  • 31
  • 1
    What is it suggesting? – Lasse V. Karlsen Apr 15 '15 at 19:42
  • 1
    Yeah, that definitely doesn't look right. – helrich Apr 15 '15 at 19:43
  • 6
    That's wrong - it should refactor it to `return new FlightRetrievalResponse {test = "this is a test"};` - What is the exact version of R# is this? – vcsjones Apr 15 '15 at 19:44
  • @LasseV.Karlsen it is suggesting to use a object initializer and set the test property inside {}. – AvetisCodes Apr 15 '15 at 19:45
  • usually it suggest a class initializer – ale Apr 15 '15 at 19:45
  • 4
    You sure you didn't pick "inline variable"? – Lasse V. Karlsen Apr 15 '15 at 19:45
  • @LasseV.Karlsen AH, that's a good thought. – vcsjones Apr 15 '15 at 19:46
  • It is exactly as vcsjones said. It should create the object by using the object initializer and return it! – Luis Lavieri Apr 15 '15 at 19:49
  • @LasseV.Karlsen no. I had cursor on the new keyword. Pressed Alt+enter and chose the option called "use object initializer". – AvetisCodes Apr 15 '15 at 19:55
  • Then yes, that looks like a bug. Which exact version of ReSharper are you using? – Lasse V. Karlsen Apr 15 '15 at 19:56
  • @LasseV.Karlsen I am using 8.2.1 thank you for your help I will go ahead and report it to JetBrains then. Just didn't want to look stupid after reporting so decided to check here first in case I was missing something. – AvetisCodes Apr 15 '15 at 19:57
  • If it is reproducible, I would try upgrading to 8.2.3, it may be a bug they've already fixed. – Lasse V. Karlsen Apr 15 '15 at 19:58
  • 1
    Not sure I was much of a help though, it sure looks like a bug, the end result is exactly what "inline variable" would produce, and if it appeared after you applied "Use object initializer" then something got crosswired in there. If I experienced this I would first upgrade, then I would try to create a reproducible and simple example, and then contact Jetbrains. They always answer rather promptly to support requests so I would definitely do that. – Lasse V. Karlsen Apr 15 '15 at 20:02
  • Though you should edit some more details into your question, like which quickfix you picked, etc. A question should be standalone and never rely on comments providing the missing details. – Lasse V. Karlsen Apr 15 '15 at 20:03
  • @LasseV.Karlsen makes sense will edit the comment to get it out there. Thank you! – AvetisCodes Apr 15 '15 at 21:04

1 Answers1

1

It seems that it is not looking correctly. It should look like:

return new FlightRetrievalResponese
{
   test = "this is a test"
};

What is your R# version?

Kevin Sch
  • 31
  • 1
  • 6