Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Incorrect optional parameter argument removal "?" #28

Closed
@andersforsell

Description

@andersforsell

@pavelgj In block.dart attrAccessorFactory the optional argument operator "?" removal was done incorrectly in #23 since one cannot distinguish "explicitly passed null" from "did not pass an optional argument" parameter. :

attrAccessorFactory(dom.Element element, String name) {
  return ([String value]) {
    if (value != null) {
      if (value == null) { // THIS CODE IS NOW DEAD
        element.removeAttribute(name);
      } else {
        element.setAttribute(name, value);
      }
      return value;
    } else {
      return element.getAttribute(name);
    }
  };
}

In a Google+ thread I saw this suggestion for handling similar problem with a special default value:

class Nothing() { const Nothing(); }
class List {
   List([n = const Nothing()]) { if(identical(n, const Nothing()) { ... } else { ... } }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions