Skip to content
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

dart2js class check error #10383

Closed
DartBot opened this issue May 2, 2013 · 11 comments
Closed

dart2js class check error #10383

DartBot opened this issue May 2, 2013 · 11 comments
Assignees
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js

Comments

@DartBot
Copy link

DartBot commented May 2, 2013

This issue was originally filed by da...@altern.org


What steps will reproduce the problem?
Try the following code:
h.TextInputElement input = new h.TextInputElement();
h.Element control = input;
print(control is h.TextInputElement);

What is the expected output? What do you see instead?
I expect to get 'true'. With Dartium, I get 'true'. With Javascript, I get 'false'.

What version of the product are you using? On what operating system?
Dart SDK 0.5.3.0_r22223. I tried several web browsers and OS.

Please provide any additional information below.
I thought this was working before ?

@madsager
Copy link
Contributor

madsager commented May 2, 2013

Added Area-HTML, Triaged labels.

@blois
Copy link
Contributor

blois commented May 2, 2013

I'm unable to repro this in either FF or Chrome, checked or unchecked.

Stephen- any idea what might be causing this?


cc @rakudrama.

@DartBot
Copy link
Author

DartBot commented May 3, 2013

This comment was originally written by da...@altern.org


Sorry, my simplified test case does not exhibit the same behavior. I will try to understand why.
I was able to work around the problem by replacing "control is TextInputElement" by "control is InputElement && (control as InputElement).type == 'text'".

@DartBot
Copy link
Author

DartBot commented May 3, 2013

This comment was originally written by da...@altern.org


Here is a modified test case - I just checked this returns false in Firefox when text is typed in the input.

  h.TextInputElement input = new h.TextInputElement();
  h.document.body.append(input);
  h.Element control = input;
  input.onInput.listen((h.Event event) => print(control is h.TextInputElement));

I guess dart2js forgets the class when the context changes...

@blois
Copy link
Contributor

blois commented May 3, 2013

Very interesting.

Simplified repro:
import 'dart:async';
import 'dart:html';

void main() {
  TextInputElement input = new TextInputElement();
  
  print(input is TextInputElement);
  Timer.run(() {
    print(input is TextInputElement);
  });
}

prints:
true
false


Removed Area-HTML label.
Added Area-Dart2JS label.

@rakudrama
Copy link
Member

tl;dr: TypeMask bug?

It gets stranger.
The first, directly visible, is-check is evaluated at run time.
This is to be expected since the factory constructor bottoms out at a JS call equivalent to:

   JS("Element", "document.createElement(#)", tag);

i.e. The inferred type of variable "input" should be subtype(Element) or subclass(Element).

The closed-over test is constant-folded to false.

$.main = function() {
  var input = $.InputElement_InputElement("text");
  $.Primitives_printString($.JSBool_methods.toString$0(typeof input === "object" && input !== null && !!$.getInterceptor(input).$isTextInputElement));
  $.Timer_run(new $.main_anon(input));
};

$$.main_anon = {"": "Closure;input_0",
  call$0: function() {
    this.input_0;
    $.Primitives_printString($.JSBool_methods.toString$0(false));
  }
};

I think this is a bug with TypeMask causing wrong constant-folding of is-checks.
In particular, this expression is returning the wrong value:

[null|subclass=Element].intersection([subtype=TextInputElement], compiler).isEmpty = true

The classes are roughly as follows, which puts InputElement in the intersection, but I failed to make a simple repro.

class Element {}
class InputElement extends Element implements ..., TextInputElement, ... {}
abstract class TextInputElement ... {}


Set owner to @kasperl.
Removed Priority-Medium label.
Added Priority-High label.

@kasperl
Copy link

kasperl commented May 6, 2013

Hmm. The missing piece of information here is that TextInputElement indirectly implements Element. That seems to throw off the intersection code in type mask. It certainly does look like a bug in the implementation of TypeMask.intersection.

@kasperl
Copy link

kasperl commented May 6, 2013

Added Accepted label.

@kasperl
Copy link

kasperl commented May 6, 2013

Fixed in r22412.


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Jul 31, 2013

This comment was originally written by da...@altern.org


Not sure if it's related, but now (control is TextInputElement) is true for a CheckboxInputElement (with Dart VM) (Dart SDK 0.6.9.2-r25388)

@blois
Copy link
Contributor

blois commented Aug 6, 2013

damieng- this is by design, a side-effect of how these types are implemented. They are all actually InputElements.

See https://code.google.com/p/dart/issues/detail?id=1684

@DartBot DartBot added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js labels Aug 6, 2013
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

5 participants