Files
sdk/tests/compiler/dart2js/inference/data/parameters_notrust.dart
T
Johnni Winther d0112f4431 Remove old frontend equivalence tests
Change-Id: I18b4b9979aea44b4dec64a5f1a32e67118b54a97
Reviewed-on: https://dart-review.googlesource.com/54222
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2018-05-09 07:55:08 +00:00

35 lines
1.4 KiB
Dart

// Copyright (c) 2018, 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';
/*element: main:[null]*/
main() {
dontTrustParameters();
}
////////////////////////////////////////////////////////////////////////////////
// Test that we don't trust the explicit type of a parameter, but do trust
// the local type of parameters in Dart 2.
//
// This means that in both Dart 1 and Dart 2 we infer the parameter type to be
// either an int or a String. In Dart 1 we don't trust the static type of the
// parameter within the method, so the return type is inferred to be either an
// int or a String. In Dart 2 we _do_ trust the static type of the parameter
// within the method and therefore infer the return type to be an int.
////////////////////////////////////////////////////////////////////////////////
/*kernel.element: _dontTrustParameters:Union([exact=JSString], [exact=JSUInt31])*/
/*strong.element: _dontTrustParameters:[exact=JSUInt31]*/
_dontTrustParameters(int /*Union([exact=JSString], [exact=JSUInt31])*/ i) {
return i;
}
/*element: dontTrustParameters:[null]*/
dontTrustParameters() {
dynamic f = _dontTrustParameters;
Expect.equals(0, f(0));
Expect.throws(/*[null|subclass=Object]*/ () => f('foo'));
}