Skip to content

Observatory evaluation problems #44497

@rakudrama

Description

@rakudrama

I'm on the inspector page for a _List.
The list contains only strings.
evaluate runtimeType gives _List<dynamic>.

Task: count the number of large strings.

Attempt 1:
where((s) => s.length > 1000000).length

The expression is not evaluated:

Unexpected exception:

ServerRpcException(org-dartlang-debug:synthetic_debug_expression:1:16: �[31mError: The getter 'length' isn't defined for the class 'Object?'.
 - 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'length'.�[39;49m
where((s) => s.length > 1000000).length
               ^^^^^^)

What appears to be happening is that the static context is inside class _List<E>.
So for static checking, E is replace by its bound Object.
While technically correct for code written in the class, this is not helpful in an inspector in the 'same' context.

Attempt 2:
Dart has a dynamic subset, right?
(this as dynamic).where((s) => s.length > 1000000).length

Execution crashes:

Unhandled exception:
type '(dynamic) => dynamic' is not a subtype of type '(dynamic) => bool' of 'test'
#0      List.Eval (:0:19)
#1      Compiler.runCodegenEnqueuer (package:compiler/src/compiler.dart:439:3)
#2      Compiler.generateJavaScriptCode (package:compiler/src/compiler.dart:315:7)
<asynchronous suspension>
#3      Compiler.runInternal (package:compiler/src/compiler.dart:277:7)
<asynchronous suspension>

Attempt 3:
(this as List<dynamic>).where((s) => s.length > 1000000).length
=> 194.

Suggestion: rewrite this to a variable with a type as close as possible to the dynamic type.

/cc @jacob314 I could not figure out how to get devtools to evaluate in this context to see if it has the same problem.
/cc @leafpetersen The dynamic evaluation case in debugging does not work as well as Dart 1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions