Files
sdk/runtime/lib/function.dart
T
Paul Berry ba2417fdc0 Fix SDK errors due to inconsistent inheritance of Operator==.
The informal spec for strong mode top level inference
(https://github.com/dart-lang/sdk/pull/28218) says "If there are
multiple overridden/implemented methods, and any two of them have
non-equal types (declared or inferred) for a parameter position which
is being inferred for the overriding method, it is an error."

This CL fixes several SDK errors that arise from this rule.  For
example, the classes _Closure, Function, and Object contained members
declared as follows:

    class _Closure implements Function {
      bool operator ==(other) ...
    }
    class Function {
      bool operator ==(Object other) ...
    }
    class Object {
      bool operator ==(other) ...
    }

The type of Object's operator == was (dynamic) -> bool; the type of
Function's operator == was (Object) -> bool; therefore the type of
_Closure's operator == (which overrides both, since _Closure extends
Object and implements Function) cannot be inferred and must be
specified.

A similar situation exists for _Double and _IntegerImplementation
(both implement num, which declares operator == to have type (Object)
-> bool), and _Uri (which implements Uri, which declares operator ==
to have type (Object) -> bool).

This CL fixes the error by specifying the type explicitly in the
classes _Closure, _Double, _IntegerImplementation, and _Uri.

Change-Id: I91f7ceef8549399d438ba4be8c408493b3f338db
Reviewed-on: https://dart-review.googlesource.com/28100
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-12-11 13:02:19 +00:00

45 lines
1.6 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// part of "core_patch.dart";
class _Closure implements Function {
bool operator ==(Object other) native "Closure_equals";
int get hashCode {
if (_hash == null) {
_hash = _computeHash();
}
return _hash;
}
_Closure get call => this;
_Closure _clone() native "Closure_clone";
int _computeHash() native "Closure_computeHash";
// No instance fields should be declared before the following 4 fields whose
// offsets must be identical in Dart and C++.
// The following fields are declared both in raw_object.h (for direct access
// from C++ code) and also here so that the offset-to-field map used by
// deferred objects is properly initialized.
// Caution: These fields are not Dart instances, but VM objects. Their Dart
// names do not need to match the C++ names, but they must be private.
var _instantiator_type_arguments;
var _function_type_arguments;
var _function;
var _context;
// Note: _Closure objects are created by VM "magically", without invoking
// constructor. So, _Closure default constructor is never compiled and
// detection of default-initialized fields is not performed.
// As a consequence, VM incorrectly assumes that _hash field is not
// nullable and may incorrectly remove 'if (_hash == null)' in get:hashCode.
// This initializer makes _hash field nullable even without constructor
// compilation.
var _hash = null;
}