Re: [analyzer-discuss] Dart analyzer returns dynamic instead of the concrete type.

26 views
Skip to first unread message

Brian Wilkerson

unread,
Jul 21, 2022, 3:11:34 PM7/21/22
to Dart Analyzer Discussion
I'm not sure what's causing the behavior you're seeing.

The analyzer typically only inserts the type `dynamic` when it's unable to resolve something. For example, if there's code of the form `a + b`, and the name `a` isn't defined in the current scope, then it will give the expression `a` a type of `dynamic`, which in turn leads to `a + b` having a type of `dynamic`.

Assuming the code is not expected to have any errors in it, the most common source of a problem like that would be if `dart pub` hadn't been run so that there's no `package_config.json` file. (The analyzer uses that file to figure out how to resolve `package:` URIs.) Given that you said that you got types for some classes and not others, that seems less likely to be the cause of the problem, but would still be worth double-checking.

Also, the text that you included (starting with `(let [library-element-result`) looks kind of like a kernel dump. Are you sure you're using the `analyzer` package and not the front-end?

On Wed, Jul 20, 2022 at 7:34 AM Baptiste Dupuch <baptist...@gmail.com> wrote:
I am one of the maintainer of ClojureDart and we rely on the Analyzer to generate types.
While working on the v2 of our analyzer (live process instead of long pre-analyze when running the compilo) I got dynamic instead of the concrete type but only for some classes.

For example for the file 6.1.2 package, I got all informations for all libs except the `local` one where I do retrieve the `LocalFileSystem` classes but with all dynamic classes.

```
(let [library-element-result
          (-> session
            (.getLibraryByUri
              "file:///Users/baptistedupuch/.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/local.dart")
            await)]
      (when (dart/is? library-element-result re/LibraryElementResult)
        (let [library-element (.element ^re/LibraryElementResult library-element-result)
              methods (-> library-element
                        .exportNamespace
                        ^e/ClassElement (.get "LocalFileSystem"))]
          (prn methods))))
```

Basically I create a session and retrieve the Library, all is working, I am dumping the `LocalFileSystem` class and all methods except constructors are dynamic.
+ it does not find supertypes but the Object one.

I am kind of lost to be honest

Thanks a lot for your time, 
Baptiste

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/e7852e55-59a8-42fd-a94c-224922684375n%40dartlang.org.
Reply all
Reply to author
Forward
0 new messages