-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Comments
Added Area-Dart2JS, Triaged labels. |
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. |
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? |
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: |
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/ |
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%) Thanks for your blazing fast response! |
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. |
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. |
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. |
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. |
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? |
That would work! |
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. |
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! |
Marking as fixed, but it would still be great with external verification. Added Fixed label. |
This comment was originally written by @paresy r37254 fixes the issue for me. Thanks! |
Thanks for the update. The fix has shipped to the dev channel in version 1.5.0-dev.4.11. Added Verified label. |
The fix is now also available on the stable channel in version 1.4.3. |
This issue was originally filed by @paresy
What steps will reproduce the problem?
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;
}
}
The text was updated successfully, but these errors were encountered: