Skip to content

Commit

Permalink
Use static dispatch for dynamic on Object methods
Browse files Browse the repository at this point in the history
Fixes #510

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1919173004 .
  • Loading branch information
harryterkelsen committed Apr 27, 2016
1 parent 6a7e3ca commit bc0536a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/dev_compiler/lib/src/compiler/code_generator.dart
Expand Up @@ -3139,6 +3139,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// If the target may be an extension type, we also use static dispatch
// as we don't symbolize object properties like hashCode.
return isNullable(target) ||
type.isDynamic ||
(_extensionTypes.contains(type.element) && target is! SuperExpression);
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/dev_compiler/test/codegen/expect/language-all.js
Expand Up @@ -67577,6 +67577,24 @@ dart_library.library('hash_map_null_key_foreach_test', null, /* Imports */[
// Exports:
exports.hash_map_null_key_foreach_test = hash_map_null_key_foreach_test;
});
dart_library.library('hashcode_dynamic_test', null, /* Imports */[
'dart_sdk',
'expect'
], function(exports, dart_sdk, expect) {
'use strict';
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const expect$ = expect.expect;
const hashcode_dynamic_test = Object.create(null);
hashcode_dynamic_test.main = function() {
let x = 3;
expect$.Expect.equals(3, dart.hashCode(x));
};
dart.fn(hashcode_dynamic_test.main, dart.void, []);
// Exports:
exports.hashcode_dynamic_test = hashcode_dynamic_test;
});
dart_library.library('hello_dart_test', null, /* Imports */[
'dart_sdk'
], function(exports, dart_sdk) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/dev_compiler/test/codegen/language/hashcode_dynamic_test.dart
@@ -0,0 +1,10 @@
// Copyright (c) 2016, 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.

import "package:expect/expect.dart";

void main() {
dynamic x = 3;
Expect.equals(3, x.hashCode);
}

0 comments on commit bc0536a

Please sign in to comment.