Skip to content

Implicit method closures aren't canonicalized #3100

Closed
@DartBot

Description

@DartBot

This issue was originally filed by @bp74


What steps will reproduce the problem?

  1. Here is a sample which shows the problem:

class Test1 {
  Test1() {
    document.body.on.click.add(_onBodyClick);
  }
  _onBodyClick(event) {
    print("Test1: onBodyClick");
    document.body.on.click.remove(_onBodyClick);
  }
}

class Test2 {
  EventListener _eventListener;
  Test2() {
    _eventListener = _onBodyClick;
    document.body.on.click.add(_eventListener);
  }
  _onBodyClick(event) {
    print("Test2: onBodyClick");
    document.body.on.click.remove(_eventListener);
  }
}

void main() {
  Test1 test1 = new Test1();
  Test2 test2 = new Test2();
}

What is the expected output? What do you see instead?

Both classes add an EventListener to the click event of the body, but only the "Test2" class can remove the EventListener again. The funny thing is that it is the same in the Dart-VM and in all browsers when compilied to JavaSscript. It almost looks like "works as desingend" but if this is by purpose i think it should be changed.

What version of the product are you using? On what operating system?
Dart Build 7696 32 bit, Windows 7 64 bit

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-duplicateClosed in favor of an existing report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions