fix #27353, support @checked covariant parameters in DDC

Seems pretty straightforward. Just added a simple test for now.

R=leafp@google.com

Review URL: https://codereview.chromium.org/2340463009 .
This commit is contained in:
John Messerly 2016-09-15 15:42:04 -07:00
parent 47cc06ae66
commit a4734d4b33
4 changed files with 47 additions and 16 deletions

View file

@ -2179,13 +2179,13 @@ class CodeGenerator extends GeneralizingAstVisitor
// TODO(jmesserly): various problems here, see:
// https://github.com/dart-lang/dev_compiler/issues/116
var paramType = param.element.type;
if (node is MethodDeclaration && _unsoundCovariant(paramType, true)) {
if (node is MethodDeclaration &&
(param.element.isCovariant || _unsoundCovariant(paramType, true)) &&
!_inWhitelistCode(node)) {
var castType = _emitType(paramType,
nameType: options.nameTypeTests || options.hoistTypeTests,
hoistType: options.hoistTypeTests);
if (!_inWhitelistCode(node)) {
body.add(js.statement('#._check(#);', [castType, jsParam]));
}
body.add(js.statement('#._check(#);', [castType, jsParam]));
}
}
return body.isEmpty ? null : _statement(body);

View file

@ -159,9 +159,9 @@ packages:
version: "0.12.0+2"
meta:
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
path: "../meta"
relative: true
source: path
version: "1.0.3"
mime:
description:

View file

@ -16,6 +16,7 @@ dependencies:
func: ^0.1.0
html: ^0.12.0
js: ^0.6.0
meta: ^1.0.3
path: ^1.3.0
pub_semver: ^1.1.0
source_maps: ^0.10.0
@ -31,15 +32,9 @@ dev_dependencies:
webdriver: ^1.1.0
dependency_overrides:
# This is here until we can update package:test and dart_style
analyzer:
path: ../analyzer
# Depend directly on packages in the same repositiory
analyzer: { path: ../analyzer }
meta: { path: ../meta }
environment:
sdk: ">=1.12.0 <2.0.0"
executables:
# Similar to "analyzer.dart" and its command line "dartanalyzer" we use
# "dartdevc".
dartdevc: dartdevc
dev_compiler: dartdevc

View file

@ -0,0 +1,36 @@
// 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";
import 'package:meta/meta.dart' show checked;
// Test runtime behavior of @checked
class View {
addChild(View v) {}
transform(View fn(View v)) {}
}
class MyView extends View {
addChild(@checked MyView v) {}
transform(@checked MyView fn(Object v)) {}
}
main() {
dynamic mv = new MyView();
dynamic v = new View();
mv.addChild(mv);
Expect.throws(() => mv.addChild(v));
mv.transform((_) => new MyView());
// TODO(jmesserly): these *should* be a cast failures, but DDC is currently
// ignoring function type failures w/ a warning at the console...
// * -> * not a subtype of Object -> MyView
// Expect.throws(() => mv.transform((_) => mv));
// View -> View not a subtype of Object -> MyView
// Expect.throws(() => mv.transform((View x) => x));
}