mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 08:51:21 +00:00
Use "bool" as the downward inference context for assert conditions.
This addresses the type inference part of #30326. R=scheglov@google.com Review-Url: https://codereview.chromium.org/2997513002 .
This commit is contained in:
parent
62f4509aa0
commit
ae4cbb50af
|
@ -5195,8 +5195,16 @@ class ResolverVisitor extends ScopedVisitor {
|
|||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Object visitAssertInitializer(AssertInitializer node) {
|
||||
InferenceContext.setType(node.condition, typeProvider.boolType);
|
||||
super.visitAssertInitializer(node);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Object visitAssertStatement(AssertStatement node) {
|
||||
InferenceContext.setType(node.condition, typeProvider.boolType);
|
||||
super.visitAssertStatement(node);
|
||||
_propagateTrueState(node.condition);
|
||||
return null;
|
||||
|
|
|
@ -119,7 +119,8 @@ class KernelAssertStatement extends AssertStatement implements KernelStatement {
|
|||
@override
|
||||
void _inferStatement(KernelTypeInferrer inferrer) {
|
||||
inferrer.listener.assertStatementEnter(this);
|
||||
inferrer.inferExpression(condition, null, false);
|
||||
inferrer.inferExpression(
|
||||
condition, inferrer.coreTypes.boolClass.rawType, false);
|
||||
if (message != null) {
|
||||
inferrer.inferExpression(message, null, false);
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ library test;
|
|||
T f<T>() => null;
|
||||
|
||||
void test() {
|
||||
assert(/*@typeArgs=dynamic*/ f());
|
||||
assert(/*@typeArgs=dynamic*/ f(), /*@typeArgs=dynamic*/ f());
|
||||
assert(/*@typeArgs=bool*/ f());
|
||||
assert(/*@typeArgs=bool*/ f(), /*@typeArgs=dynamic*/ f());
|
||||
}
|
||||
|
||||
main() {}
|
||||
|
|
|
@ -5,7 +5,7 @@ import "dart:core" as core;
|
|||
static method f<T extends core::Object>() → self::f::T
|
||||
return null;
|
||||
static method test() → void {
|
||||
assert(self::f<dynamic>());
|
||||
assert(self::f<dynamic>(), self::f<dynamic>());
|
||||
assert(self::f<core::bool>());
|
||||
assert(self::f<core::bool>(), self::f<dynamic>());
|
||||
}
|
||||
static method main() → dynamic {}
|
||||
|
|
|
@ -8,14 +8,14 @@ library test;
|
|||
T f<T>() => null;
|
||||
|
||||
class C {
|
||||
C.expressionOnly() : assert(/*@typeArgs=dynamic*/ f());
|
||||
C.expressionOnly() : assert(/*@typeArgs=bool*/ f());
|
||||
C.expressionAndMessage()
|
||||
: assert(/*@typeArgs=dynamic*/ f(), /*@typeArgs=dynamic*/ f());
|
||||
: assert(/*@typeArgs=bool*/ f(), /*@typeArgs=dynamic*/ f());
|
||||
}
|
||||
|
||||
main() {
|
||||
// Test type inference of assert statements just to verify that the behavior
|
||||
// is the same.
|
||||
assert(/*@typeArgs=dynamic*/ f());
|
||||
assert(/*@typeArgs=dynamic*/ f(), /*@typeArgs=dynamic*/ f());
|
||||
assert(/*@typeArgs=bool*/ f());
|
||||
assert(/*@typeArgs=bool*/ f(), /*@typeArgs=dynamic*/ f());
|
||||
}
|
||||
|
|
|
@ -5,18 +5,18 @@ import "dart:core" as core;
|
|||
class C extends core::Object {
|
||||
constructor expressionOnly() → void
|
||||
: final dynamic #t1 = () → dynamic
|
||||
assert(self::f<dynamic>());
|
||||
assert(self::f<core::bool>());
|
||||
.call(), super core::Object::•()
|
||||
;
|
||||
constructor expressionAndMessage() → void
|
||||
: final dynamic #t2 = () → dynamic
|
||||
assert(self::f<dynamic>(), self::f<dynamic>());
|
||||
assert(self::f<core::bool>(), self::f<dynamic>());
|
||||
.call(), super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method f<T extends core::Object>() → self::f::T
|
||||
return null;
|
||||
static method main() → dynamic {
|
||||
assert(self::f<dynamic>());
|
||||
assert(self::f<dynamic>(), self::f<dynamic>());
|
||||
assert(self::f<core::bool>());
|
||||
assert(self::f<core::bool>(), self::f<dynamic>());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue