Skip to content

dart2js: wrong [empty] type inferred (works with --disable-type-inference) #18836

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

Closed
DartBot opened this issue May 15, 2014 · 19 comments
Closed
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Milestone

Comments

@DartBot
Copy link

DartBot commented May 15, 2014

This issue was originally filed by @paresy


What steps will reproduce the problem?

  1. Use the provided example code
  2. Run pub build
  3. Open the HTML file to load the example

What is the expected output? What do you see instead?
No error in console is expected.
Instead the interpreter dies with:

> Uncaught TypeError: undefined is not a function.

The forEach mixin is undefined.

What version of the product are you using? On what operating system?
1.3/1.4 is affected. 1.2 is NOT affected. Windows x64.

Example:

import 'dart:html';
import 'dart:math' as math;

void main() {
  
  List bla;
  Blaclass.findMaxValue(bla);
  
}

class Blaclass {
  
  static double findMaxValue(List datas){
    
    double maxValue = double.NEGATIVE_INFINITY;
    datas.forEach( (Map dataset){
      //calculate maxValue with maximal value in list
      dataset['data'].forEach((dynamic value) {
        if (value != null)
          if (value is num){
            maxValue = math.max(value, maxValue);
          } else if (value is List){
            value.forEach( (double interValue) {
              if (interValue != null){
                maxValue = math.max(interValue, maxValue);
              }
            });
          }
      });
    });
    
    return maxValue;
  }
  
}

@dgrove
Copy link
Contributor

dgrove commented May 15, 2014

Added Area-Dart2JS, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

This comment was originally written by @paresy


Can you reproduce the problem? Do you need any other information?

Unfortunately i cannot use any newer version than 1.2 due to this problem.

@kasperl
Copy link

kasperl commented Jun 10, 2014

Not sure I understand this bug report. The 'bla' variable in main will always be null so the 'datas' parameter will always be null. Calling forEach on null is expected to throw an exception.

What am I missing?

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

This comment was originally written by @paresy


You are totally right. Then i am unable to provide a valid example of the problem i am encoutering. I will try to add screenshots of the debugger. Maybe you have got any hints in which direction i could search.

I can step trough the debugger until the point i reach the forEach$1. The screenshot 3 shows that is seems to be undefined. After going a step further i go to the point shown in screenshot 4.

I attached the JS code from Dart 1.2 in screenshot 5 which is working fine. The source from which the compiled js code is obtained was the same for screenshots 1-4 and screenshot 5.

Any hints?


Attachments:
bug1.png (8.63 KB)
bug2.png (19.58 KB)
bug3.png (14.31 KB)
bug4.png (19.47 KB)
bug5.png (7.58 KB)

@kasperl
Copy link

kasperl commented Jun 10, 2014

Thanks for the extra details! It does look freaky. The value of the 'datasets' parameter is a JavaScript array (of length 1) and that doesn't have a property named 'forEach$1' so reading that leads to undefined which cannot be invoked as a function.

Do you know where you get / compute the list that you pass to findMaxValue? Is it pulled out of another list or map?

Could you try to compile your code with 'dart2js --dump-info' and find the findMaxValue$1 function in there? I'm curious about the type we infer for the datasets parameter. It looks like we believe it cannot be a builtin JS type (such as Array) and that seems wrong.

If you've got a few minutes to try the latest (unreleased) SDK build, it would be very interesting to know if the issue still reproduces:

   http://gsdview.appspot.com/dart-archive/channels/dev/raw/37161/sdk/

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

This comment was originally written by @paresy


The newest SDK did not resolve the error. Here is the info you requested:

+method /* (dynamic) -> double / findMaxValue 267 bytes (0%)
+closure /
(dynamic) -> dynamic */ <unnamed> 113 bytes (0%)
Inferred return type [subtype=num]
Inferred side effects Depends on [] field store static store, Changes [] field static.
Generated code 154 bytes (0%)
Inferred parameter datasets [empty]
function(datasets) {
  var t1 = {};
  t1.maxValue_0 = -1 / 0;
  datasets.forEach$1(0, new B.DartChart_findMaxValue_closure(t1));
  return t1.maxValue_0;
}

Thanks for your blazing fast response!

@kasperl
Copy link

kasperl commented Jun 10, 2014

It does look like it's related to dart2js inferring the wrong type. You can try to disable it with:

   $ dart2js --disable-type-inference ...

and see if that solves the problem. It looks like we think you will never be able to produce a value for the 'datasets' parameter because we infer that the parameter type represents the [empty] value set.

Next step is probably to look at where you call findMaxValue from.

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

This comment was originally written by @paresy


Disabling type inference did the trick. I know that it increases the file size, but at least it is working. Thanks for this hint!

I also tried to rebuild the test-project functions and classes to match my project but did not succeed to replicate the error state.

@kasperl
Copy link

kasperl commented Jun 10, 2014

Thanks for trying to produce a simpler test case for us! Much appreciated.

This could be related to issue #18717.


Set owner to @herhut-ggl.
Removed Priority-Unassigned label.
Added Priority-High label.
Changed the title to: "dart2js: wrong [empty] type inferred (works with --disable-type-inference)".

@ghost
Copy link

ghost commented Jun 10, 2014

Could you describe the setup of your application? It would help if you could describe the call trace that leads to the invocation of findMaxValue. Are there any closures involved? What triggers the computation?

I would really like to get to the bottom of this and issue #18717 but without reproducing it locally finding the issue is quite hard.


Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

This comment was originally written by @paresy


I can send you the source code of both, the library that is involved and the main application?

@ghost
Copy link

ghost commented Jun 10, 2014

That would work!

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

This comment was originally written by @paresy


You have mail and i attached the stacktrace.


Attachment:
bug6.png (21.24 KB)

@ghost
Copy link

ghost commented Jun 10, 2014

Thanks for your help in tracking this down. I have identified the issue and a patch is under review. You can follow its status at https://codereview.chromium.org/326903004/. Once reviewed, I hope to get this into the 1.5 release.


Added this to the 1.5 milestone.
Added Started label.

@kasperl
Copy link

kasperl commented Jun 12, 2014

The fix has been submitted in r37254 and we've got a build that you can try:

http://gsdview.appspot.com/dart-archive/channels/be/raw/37255/

Let us know if the issue is resolved in that build. Thanks again for all the feedback!

@kasperl
Copy link

kasperl commented Jun 13, 2014

Marking as fixed, but it would still be great with external verification.


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Jun 13, 2014

This comment was originally written by @paresy


r37254 fixes the issue for me. Thanks!

@kasperl
Copy link

kasperl commented Jun 13, 2014

Thanks for the update. The fix has shipped to the dev channel in version 1.5.0-dev.4.11.


Added Verified label.

@kasperl
Copy link

kasperl commented Jun 17, 2014

The fix is now also available on the stable channel in version 1.4.3.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants