Question about inspection 'Constant, [...] with same name is already declared in scope'
I was wondering about the semantics of the inspection 'Constant, module or class with same name is already declared in scope'. Suppose I have the following setup:
File a.rb:
require 'b'
module Demo
CONSTANT = 42
end
File b.rb:
require 'a'
module Demo
end
CONSTANT = 42 is marked as already being declared in scope, which I didn't expect to be the case because there really is only one declaration. Is this behavior intentional?
请先登录再写评论。
Which RubyMine version do you use? I don't see such behaviour in RubyMine 3.1 Beta. But on run-time you will get similar error.

P.S: The warning appeared after I'd reloaded the project. But seems it is reasonable according to run-time bahaviour.
This is the IDEA Ruby plugin 3.1.17317. But you're right: I get the same warning when running the script. I must have missed that. So I guess, the inspection result is correct after all.
What would be the best way to avoid that warning? It's not always possible to know ahead of time which files will be included from which file.
Thanks
It seems to be a little more complicated than that. I just recreated that simple test case from above and CONSTANT is not highlighted as warning (anymore???). However, I see this warning in my project. There is no other declaration of that symbol in my project (at least none that I could find with "Find in Path") and i doubt that it clashes with standard ruby libs.

Got it. I'm not sure how this is triggered, but something is definitely not adding up here.


The warning goes aways, if I add a new line:
Removing that first line still does not show the warning. It only reappears after making more changes.
In your example a and b includes each other recursively. If you launch "b" you wont see any warning on runtime.
When you open file in Ruby plugin (or RubyMine) it analyzes all files which are required in current file from its point of view. So each file gives a bit different tree. This algorithm is more complicated in case of Rails projects because there are lots of implicit dynamic "require" calls.
I assume it is related to some bugs or behaviour of internal caching and optimizations. In future Ruby plugin / RubyMine version we are going to rewrite our code insight engine so I don't want to submit it as a bug but if you want you can sumbit it - http://youtrack.jetbrains.net/issues/ruby.
I agree that there should be a warning in a.rb and that there is no problem if I run b.rb.
However, I get inconsistent results for a.rb depending on the sequence of edits that I make (see my screenshots below). I believe, this shouldn't be the case. At least not for this trivial scenario.
I filed RUBY-7799 for this. I guess, I'll just have to turn that warning off for the time being.