Files
sdk/pkg/front_end/testcases/inference/bug30624.dart
T
Paul Berry 068c78e9d7 Change type inference of ?? to match analyzer, prep for future fixes.
Previous to this CL, inference of `??` matched the behavior specified
in the informal spec (https://github.com/dart-lang/sdk/pull/29371),
whereas inference of `?:` matched analyzer behavior.

In the long run, we want the behavior of both `??` and `?:` to match
the spec (note that the spec is still being debated, so this is a
moving target).  But for now, to ease the transition to the new front
end, we want to match analyzer behavior.

With this CL, the inference for `??` is changed to match analyzer
behavior, and a boolean is introduced to make it easy for us to switch
to the behavior specified in the informal spec when it's appropriate
to do so.

Should address the inconsistency pointed out in #30624.

Change-Id: I33d95cd59e4c7e474f3ba27491be87c1bf66d85e
Reviewed-on: https://dart-review.googlesource.com/3421
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-06 15:16:43 +00:00

44 lines
1.1 KiB
Dart

// Copyright (c) 2017, 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.
/*@testedFeatures=inference*/
library test;
void foo<E>(C<E> c, int cmp(E a, E b)) {}
class C<E> {
void barA([int cmp(E a, E b)]) {
/*@typeArgs=C::E*/ foo(this, cmp ?? _default);
}
void barB([int cmp(E a, E b)]) {
/*@typeArgs=C::E*/ foo(this, cmp ?? (_default as int Function(E, E)));
}
void barC([int cmp(E a, E b)]) {
int Function(E, E) v = _default;
/*@typeArgs=C::E*/ foo(this, cmp ?? v);
}
void barD([int cmp(E a, E b)]) {
foo<E>(this, cmp ?? _default);
}
void barE([int cmp(E a, E b)]) {
/*@typeArgs=C::E*/ foo(
this, cmp /*@target=Object::==*/ == null ? _default : cmp);
}
void barF([int cmp(E a, E b)]) {
/*@typeArgs=C::E*/ foo(
this, cmp /*@target=Object::==*/ != null ? cmp : _default);
}
static int _default(a, b) {
return /*@target=int::unary-*/ -1;
}
}
main() {}