Skip to content
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

Using not Code for DeclarationCode.fromParts() #55441

Closed
scheglov opened this issue Apr 11, 2024 · 4 comments
Closed

Using not Code for DeclarationCode.fromParts() #55441

scheglov opened this issue Apr 11, 2024 · 4 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature P2 A bug or feature request we're likely to work on

Comments

@scheglov
Copy link
Contributor

From https://docs.google.com/document/d/1x13R1AsPtbF06oq-iE91EUrygqUDsnfRI8X3jdTkmjI

Passing MethodDeclaration.returnType to MemberDeclarationBuilder.declareInType(DeclarationCode.fromParts( ... ))
causes the analyzer server to hang. Generated code stops updating until the analyzer server is restarted.

It's hard to discover that you in fact need to pass MethodDeclaration.returnType.code here. The generic typing 
of List<Object> for the argument of  DeclarationCode.fromParts is not helpful.
@scheglov scheglov added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on feature-macros Implementation of the macros feature labels Apr 11, 2024
@scheglov scheglov self-assigned this Apr 11, 2024
@scheglov
Copy link
Contributor Author

Interesting, I don't see a hard hang in unit tests for the element model and resolution.
But when I do it in IntelliJ, DAS sends server error.

## Dart analysis issue

Bad state: Unrecognized code part Instance of 'NamedTypeAnnotationImpl'

## Version information

- Dart SDK 3.5.0-edge.9315ae565160afea5ae049bde6aacd0cc077b07d
- Dart IntelliJ 241.15845
- IntelliJ IDEA 2024.1
- Mac OS X 14.4.1

## Details

Bad state: Unrecognized code part Instance of 'NamedTypeAnnotationImpl'

#0 SerializeCode.serialize (package:_macros/src/executor/serialization_extensions.dart:609:13)
#1 MacroExecutionResultImpl.serialize (package:_macros/src/executor/response_impls.dart:479:22)
#2 SerializeNullable.serializeNullable (package:_macros/src/executor/serialization_extensions.dart:495:12)
#3 SerializableResponse.serialize (package:_macros/src/executor/protocol.dart:136:18)
#4 MacroExpansionClient._handleMessage. (package:_macros/src/executor/client.dart:136:16)

#5 MacroExpansionClient._handleMessage (package:_macros/src/executor/client.dart:118:5)


## Debug log

1712867529318 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1712867529344 <= {"event":"analysis.errors","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","errors":[{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"/Users/scheglov/da...
1712867529345 <= {"event":"analysis.highlights","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","regions":[{"type":"DIRECTIVE","offset":0,"length":11},{"type":"BUILT_IN","offset":0,"length...
1712867529345 <= {"event":"analysis.navigation","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","regions":[{"offset":30,"length":1,"targets":[0]},{"offset":41,"length":3,"targets":[1]}],"t...
1712867529345 <= {"event":"analysis.outline","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","kind":"LIBRARY","outline":{"element":{"kind":"COMPILATION_UNIT","name":"","location":{"f...
1712867529345 <= {"event":"analysis.overrides","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","overrides":[]}}
1712867529378 <= {"id":"19590","result":{"replacementOffset":8,"replacementLength":1,"suggestions":[{"kind":"IMPORT","relevance":900,"completion":"append.dart","selectionOffset":11,"selectionLength":0...
1712867529382 <= {"event":"analysis.errors","params":{"file":"/Users/scheglov/dart/test/bin/test.dart","errors":[{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"/Users/scheglov/dar...
1712867529413 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1712867529414 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1712867529414 <= {"event":"analysis.implemented","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","classes":[],"members":[]}}
1712867529443 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1712867530127 => {"id":"19591","method":"analysis.updateContent","params":{"files":{"/Users/scheglov/dart/test/bin/test3.dart":{"type":"add","content":"import 'appen';\n\n@CrashMe()\nclass A {\n void...
1712867530130 <= {"id":"19591","result":{}}
1712867530130 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1712867530169 <= {"event":"analysis.errors","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","errors":[{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"/Users/scheglov/da...
1712867530169 <= {"event":"analysis.highlights","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","regions":[{"type":"DIRECTIVE","offset":0,"length":15},{"type":"BUILT_IN","offset":0,"length...
1712867530169 <= {"event":"analysis.navigation","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","regions":[{"offset":34,"length":1,"targets":[0]},{"offset":45,"length":3,"targets":[1]}],"t...
1712867530169 <= {"event":"analysis.outline","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","kind":"LIBRARY","outline":{"element":{"kind":"COMPILATION_UNIT","name":"","location":{"f...
1712867530169 <= {"event":"analysis.overrides","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","overrides":[]}}
1712867530173 <= {"event":"analysis.errors","params":{"file":"/Users/scheglov/dart/test/bin/test.dart","errors":[{"severity":"ERROR","type":"COMPILE_TIME_ERROR","location":{"file":"/Users/scheglov/dar...
1712867530206 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1712867530206 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1712867530206 <= {"event":"analysis.implemented","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","classes":[],"members":[]}}
1712867530231 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1712867530474 => {"id":"19592","method":"analysis.updateContent","params":{"files":{"/Users/scheglov/dart/test/bin/test3.dart":{"type":"add","content":"import 'append.dart';\n\n@CrashMe()\nclass A {\n...
1712867530479 => {"id":"19593","method":"edit.getFixes","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","offset":2},"clientRequestTime":1712867530479}
1712867530479 <= {"id":"19592","result":{}}
1712867530479 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1712867530485 => {"id":"19594","method":"edit.getAssists","params":{"file":"/Users/scheglov/dart/test/bin/test3.dart","offset":19,"length":0},"clientRequestTime":1712867530485}

@scheglov
Copy link
Contributor Author

Ah, I run unit tests with asserts enabled, so the mistake does not allow you to create such invalid Code.fromParts() at all. But if you don't have asserts enabled, e.g. when you run DAS from IntelliJ, you can. But then it hard crash later, at the point where it is not an assert. Which means that the first point also should be not just an assert, but full check. Or better typing.

@scheglov
Copy link
Contributor Author

The reason it hangs is that the analyzer does not get a response from the macro running isolate.
The macro isolate created the result, and crashed trying to send it, below in serialize().

        case MessageType.executeDeclarationsPhaseRequest:
          ExecuteDeclarationsPhaseRequest request =
              ExecuteDeclarationsPhaseRequest.deserialize(deserializer, zoneId);
          (await _executeDeclarationsPhase(request, sendRequest))
              .serialize(serializer);

If we checked inside Code.fromParts(), we would send the exception result instead.

@scheglov
Copy link
Contributor Author

copybara-service bot pushed a commit that referenced this issue Apr 16, 2024
Bug: #55441
Change-Id: I27fd2cbdd750317a40583788690447d54df6a037
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362440
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature P2 A bug or feature request we're likely to work on
Projects
Development

No branches or pull requests

1 participant