Skip to content

Include import prefixes on type error messages - DDC #33695

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

Open
srawlins opened this issue Jun 28, 2018 · 0 comments
Open

Include import prefixes on type error messages - DDC #33695

srawlins opened this issue Jun 28, 2018 · 0 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dev-compiler

Comments

@srawlins
Copy link
Member

Similar to #33667 (CFE) and #33693 (VM).

Reproduction for DDC is simple. It's like 3 steps.

  1. First, create a new directory, for a package. You'll need a whole package.

  2. Next create a pubspec.yaml with lots of goodies:

    name: examples.hello_world
    
    environment:
      sdk: ">=2.0.0-dev.60.0 <2.0.0"
    
    dev_dependencies:
      build_runner: ^0.9.0
      build_test: ^0.10.2+5
      build_web_compilers: ^0.4.0+4
  3. Of course, pub get that jazz.

  4. Make a web app in two easy steps. So easy.

    1. Write this into web/index.html:
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Hello World</title>
      <link rel="icon" type="image/png" href="favicon.png">
      <script defer src="main.dart.js"></script>
    </head>
    <body>
    </body>
    </html>
    1. Write this into web/main.dart:
    import 'dart:math' as math;
    
    // Poorly named wrapper for math.Random
    class Random {
      math.Random inner;
    
      Random(this.inner);
    }
    
    void main() {
      List<Random> list = new List<Random>()..add(new Random(new math.Random(7)));
      addRandom(list.map((e) => e.inner));
    }
    
    addRandom(List<math.Random> list) => list..add(new math.Random());
  5. Install webdev: pub global active webdev.

  6. Run webdev serve.

  7. We're almost there, home stretch.

  8. Load up http://localhost:8080 in a browser.

  9. Look at the JavaScript console. Click the expand buttons until you see:

    "Type 'MappedListIterable<Random, Random>' is not a subtype of expected type 'List'."

OK, the issue is that that error message is a great clue if we're game for a puzzle. But for the more casual developer, I think we should show the prefix that they wanted to use:

"Type 'MappedListIterable<Random, math.Random>' is not a subtype of expected type 'List<math.Random>'."

This case I think illuminates how this would be useful: the Randoms are a red herring. The issue is that Iterable<blah-blah> is not List<blah-blah>. (I'll open a separate issue for the mysterious MappedListIterable showing up in errors, a class that I neither wrote, nor can find in SDK docs 😮 .)

@vsmenon vsmenon added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. web-dev-compiler
Projects
None yet
Development

No branches or pull requests

3 participants