62596baeda
I will soon be adding functionality to keep track of users' attempts to promote things that aren't promotable (`this` as well as property gets), so that we can give the user more useful error messages. There's some some danger that adding this tracking logic will accidentally cause such expressions to be promoted. These tests should help guard against unintentional behavioral changes. Change-Id: I00d6c964c660602a3589a3efcf0042a11eaea5db Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178882 Reviewed-by: Bob Nystrom <rnystrom@google.com>
111 lines
2.2 KiB
Dart
111 lines
2.2 KiB
Dart
// Copyright (c) 2020, 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 '../../static_type_helper.dart';
|
|
|
|
// This test verifies that neither an `== null` nor an `is` test can promote the
|
|
// type of `this`. (In principle, we could soundly do so, but we have decided
|
|
// not to do so at this time).
|
|
|
|
class C {
|
|
void equality() {
|
|
if (this == null) {
|
|
this.expectStaticType<Exactly<C>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<C>>();
|
|
}
|
|
}
|
|
|
|
void isSameType() {
|
|
if (this is C) {
|
|
this.expectStaticType<Exactly<C>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<C>>();
|
|
}
|
|
}
|
|
|
|
void isSubtype() {
|
|
if (this is D) {
|
|
this.expectStaticType<Exactly<C>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<C>>();
|
|
}
|
|
}
|
|
}
|
|
|
|
class D extends C {}
|
|
|
|
class E {}
|
|
|
|
class F extends E {}
|
|
|
|
extension on E {
|
|
void equality() {
|
|
if (this == null) {
|
|
this.expectStaticType<Exactly<E>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<E>>();
|
|
}
|
|
}
|
|
|
|
void isSameType() {
|
|
if (this is E) {
|
|
this.expectStaticType<Exactly<E>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<E>>();
|
|
}
|
|
}
|
|
|
|
void isSubtype() {
|
|
if (this is F) {
|
|
this.expectStaticType<Exactly<E>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<E>>();
|
|
}
|
|
}
|
|
}
|
|
|
|
class G {}
|
|
|
|
extension on G? {
|
|
void equality() {
|
|
if (this == null) {
|
|
this.expectStaticType<Exactly<G?>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<G?>>();
|
|
}
|
|
}
|
|
|
|
void isSameType() {
|
|
if (this is G?) {
|
|
this.expectStaticType<Exactly<G?>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<G?>>();
|
|
}
|
|
}
|
|
|
|
void isSubtype() {
|
|
if (this is G) {
|
|
this.expectStaticType<Exactly<G?>>();
|
|
} else {
|
|
this.expectStaticType<Exactly<G?>>();
|
|
}
|
|
}
|
|
}
|
|
|
|
main() {
|
|
C().equality();
|
|
C().isSameType();
|
|
C().isSubtype();
|
|
E().equality();
|
|
E().isSameType();
|
|
E().isSubtype();
|
|
G().equality();
|
|
G().isSameType();
|
|
G().isSubtype();
|
|
(null as G?).equality();
|
|
(null as G?).isSameType();
|
|
(null as G?).isSubtype();
|
|
}
|