Skip to content

Bad recovery for partially-typed code before a nested function #49477

@DanTup

Description

@DanTup

In this code, invoking completion after stdout. results in unexpected results:

import 'dart:io';

void main(List<String> args) async {
  final proc = await Process.start('', []);
  proc.stdout.

  void writeMessage(String message) {}
}

Screenshot 2022-07-19 at 10 18 09

The completion list shows the same things you'd expect to see after proc., but not stdout.. Adding a semicolon to the end of the line and invoking completion before it gives the right results, so I presume something is wrong with the recovery here. The AST from the diagnostics page is below. Completion was invoked at offset 114 (after stdout.). Interestingly I can't see any tokens for writeMessage etc. in this AST, even though there is a diagnostic produced for it (offset 123-135: "function expressions can't be named") so I don't know if this AST is complete.

CompilationUnitImpl [0..156]
┊        declaredElement = /Users/danny/Desktop/dart_sample/bin/recovery.dart
┊   ImportDirectiveImpl [0..16]
┊   ┊        element = import source /Users/danny/Dev/Dart SDKs/nightly/lib/io/io.dart
┊   ┊        selectedSource = Source (uri="dart:io", path="/Users/danny/Dev/Dart SDKs/nightly/lib/io/io.dart")
┊   ┊        uriSource = Source (uri="dart:io", path="/Users/danny/Dev/Dart SDKs/nightly/lib/io/io.dart")
┊   ┊   SimpleStringLiteralImpl [7..15]
┊   ┊   ┊        value = dart:io
┊   FunctionDeclarationImpl [19..155]
┊   ┊        declaredElement = void main(List<String> args)
┊   ┊        name = main
┊   ┊   NamedTypeImpl [19..22]
┊   ┊   ┊        name = void
┊   ┊   ┊        type = void
┊   ┊   ┊   SimpleIdentifierImpl [19..22]
┊   ┊   ┊   ┊        name = void
┊   ┊   DeclaredSimpleIdentifier [24..27]
┊   ┊   ┊        name = main
┊   ┊   ┊        static element = void main(List<String> args)
┊   ┊   FunctionExpressionImpl [28..155]
┊   ┊   ┊        static type = void Function(List<String>)
┊   ┊   ┊   FormalParameterListImpl [28..46]
┊   ┊   ┊   ┊   SimpleFormalParameterImpl [29..45]
┊   ┊   ┊   ┊   ┊        declaredElement = List<String> args
┊   ┊   ┊   ┊   ┊        kind = required-positional
┊   ┊   ┊   ┊   ┊   NamedTypeImpl [29..40]
┊   ┊   ┊   ┊   ┊   ┊        name = List<String>
┊   ┊   ┊   ┊   ┊   ┊        type = List<String>
┊   ┊   ┊   ┊   ┊   ┊   SimpleIdentifierImpl [29..32]
┊   ┊   ┊   ┊   ┊   ┊   ┊        name = List
┊   ┊   ┊   ┊   ┊   ┊   ┊        static element = abstract class List<E> implements EfficientLengthIterable<E>
┊   ┊   ┊   ┊   ┊   ┊   TypeArgumentListImpl [33..40]
┊   ┊   ┊   ┊   ┊   ┊   ┊   NamedTypeImpl [34..39]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = String
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        type = String
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   SimpleIdentifierImpl [34..39]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = String
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static element = abstract class String implements Comparable<String>, Pattern
┊   ┊   ┊   ┊   ┊   DeclaredSimpleIdentifier [42..45]
┊   ┊   ┊   ┊   ┊   ┊        name = args
┊   ┊   ┊   ┊   ┊   ┊        static element = List<String> args
┊   ┊   ┊   BlockFunctionBodyImpl [48..155]
┊   ┊   ┊   ┊        isAsynchronous = true
┊   ┊   ┊   ┊        isGenerator = false
┊   ┊   ┊   ┊   BlockImpl [54..155]
┊   ┊   ┊   ┊   ┊   VariableDeclarationStatementImpl [58..98]
┊   ┊   ┊   ┊   ┊   ┊   VariableDeclarationListImpl [58..97]
┊   ┊   ┊   ┊   ┊   ┊   ┊        keyword = final
┊   ┊   ┊   ┊   ┊   ┊   ┊   VariableDeclarationImpl [64..97]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        declaredElement = Process proc
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = proc
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   DeclaredSimpleIdentifier [64..67]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = proc
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static element = Process proc
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   AwaitExpressionImpl [71..97]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = Process
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   MethodInvocationImpl [77..97]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static invoke type = Future<Process> Function(String, List<String>, {Map<String, String>? environment, bool includeParentEnvironment, ProcessStartMode mode, bool runInShell, String? workingDirectory})
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = Future<Process>
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   SimpleIdentifierImpl [77..83]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = Process
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static element = abstract class Process
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   SimpleIdentifierImpl [85..89]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = start
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static element = Future<Process> start(String executable, List<String> arguments, {String? workingDirectory, Map<String, String>? environment, bool includeParentEnvironment = true, bool runInShell = false, ProcessStartMode mode = ProcessStartMode.normal})
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = Future<Process> Function(String, List<String>, {Map<String, String>? environment, bool includeParentEnvironment, ProcessStartMode mode, bool runInShell, String? workingDirectory})
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ArgumentListImpl [90..97]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static parameter types = [String executable, List<String> arguments]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   SimpleStringLiteralImpl [91..92]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        value =
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ListLiteralImpl [95..96]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = List<String>
┊   ┊   ┊   ┊   ┊   ExpressionStatementImpl [102..154]
┊   ┊   ┊   ┊   ┊   ┊   PropertyAccessImpl [102..135]
┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = dynamic
┊   ┊   ┊   ┊   ┊   ┊   ┊   SimpleIdentifierImpl [102..105]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = proc
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static element = Process proc
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = Process
┊   ┊   ┊   ┊   ┊   ┊   ┊   SimpleIdentifierImpl [135..135]
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        name = (
┊   ┊   ┊   ┊   ┊   ┊   ┊   ┊        static type = dynamic

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestlegacy-area-front-endLegacy: Use area-dart-model instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions