-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Analyzer: adding dartdoc causes spurious message for unused local variable #25064
Comments
Actually, I was able to reproduce it by pasting the text above into my standard "test.dart" test file. |
I can reproduce it as well. I'll look into it. |
Another symptom: the outline disappears. Using the diagnostics page, it looks like the AST structure disappears: CompilationUnit [0..336] After changing "///" to "//" it appears again. |
A log entry [1] indicates that the bug happens when _tryPoorMansIncrementalResolution in context.dart succeeds. I haven't been able to make that happen outside Atom yet. [1] 1452586433119:Perf:analysis_incremental:11:success=true,context_id=0,code_length=337 |
@scheglov Any ideas? |
There is a _resolveCommentDoc method specifically for resolving comment docs. I don't see the bug, but perhaps it's failing somehow. |
I figured out why my integration test didn't reproduce the same problem as I saw in Atom. It turns out that the behavior is different in checked mode. The analysis server swallows the exception and keeps going using non-incremental resolution, so I wasn't able to reproduce the bug. Here is the stack trace: stderr: [2016-01-12 17:00:11.626932] type 'ClassDeclaration' is not a subtype of type 'Comment' of 'oldComment'. We should probably audit the analyzer for places where we catch all exceptions and make sure that checked mode failures are handled properly. For some reason this exception wasn't logged until I turned on the special incremental resolution logger. In this particular case, the culprit is |
Looking at _findFirstDifferentToken, it appears that a _TokenPair will have type COMMENT_DOC if either token is preceded by a doc comment, and the doc comments are different. (The tokens themselves could be different as well, because the comments are compared first.) In PoorMansIncrementalResolver.resolve(), it will call _resolveCommentDoc for any pair of this type. _resolveCommentDoc appears to be written assuming that _findNodeCovering will return a Comment for both token positions but this doesn't seem to be the case. |
@scheglov Any advice? |
It looks like doc comments are represented in the AST, but regular comments are not. Therefore, when _resolveCommentDoc calls _findNodeCovering() with the offset of a comment that is not a doc comment, the closest match is the parent node, which in this case is a ClassDeclaration, not a Comment. In checked mode, this throws an exception. In non-checked mode, it calls NodeReplacer.replace() to remove the ClassDeclaration and replace it with the DocComment. So this code needs to return false when it doesn't receive a pair of doc comments. |
I was just about to send a patch for review, but you beat me to it. |
…ation. R=brianwilkerson@google.com, skybrian@google.com BUG= #25064 Review URL: https://codereview.chromium.org/1581293002 .
(This is not reproducible but I thought I't report it anyway, mostly as an example of a bug where it's difficult to gather enough information to reproduce it.)Using Atom 1.2.0, dartlang 0.4.15, dart sdk 1.13.0.
Sometimes converting a '//' to a '///' above a getter causes spurious messages for all local
variables inside the the getter:
Info: 'the value of the local variable 'XXX' is not used'
Deleting the final slash (so it's no longer a doc comment)
will remove the messages, as will reanalyzing sources.
I was able to reproduce the error locally in a different project, using the code below [1]. To trigger the error, type "/" for the comment on 'title'.
However, I was unable to reproduce this after copying the same Dart code to a new file (also in the second project), so I suspect you won't be able to reproduce it either. I edited the code to remove unnecessary cruft, and I don't remember which edits I made. It seems like we need a way of dumping more information about the current state of a Dart file?
I also tried looking at Analyzer diagnostics, but ran into (dart-atom/dart#588 (comment)) so I don't have any more information.
[1]
The text was updated successfully, but these errors were encountered: