c191551fac
TEST=Covered by existing tests. Change-Id: Ied8be1874164e68e0a3a48e1b2f9a33310071381 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183009 Commit-Queue: Dmitry Stefantsov <dmitryas@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
123 lines
3.0 KiB
Plaintext
123 lines
3.0 KiB
Plaintext
library /*isNonNullableByDefault*/;
|
|
//
|
|
// Problems in library:
|
|
//
|
|
// pkg/front_end/testcases/nnbd/switch_nullable_enum.dart:7:5: Error: A non-null value must be returned since the return type 'int' doesn't allow null.
|
|
// int method1(Enum? e) {
|
|
// ^
|
|
//
|
|
import self as self;
|
|
import "dart:core" as core;
|
|
import "dart:_internal" as _in;
|
|
|
|
class Enum extends core::Object /*isEnum*/ {
|
|
final field core::int index;
|
|
final field core::String _name;
|
|
static const field core::List<self::Enum> values = #C7;
|
|
static const field self::Enum e1 = #C3;
|
|
static const field self::Enum e2 = #C6;
|
|
const constructor •(core::int index, core::String _name) → self::Enum
|
|
: self::Enum::index = index, self::Enum::_name = _name, super core::Object::•()
|
|
;
|
|
method toString() → core::String
|
|
return this.{self::Enum::_name};
|
|
}
|
|
static method method1(self::Enum? e) → core::int {
|
|
switch(e) {
|
|
#L1:
|
|
case #C3:
|
|
case #C6:
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return let final Never #t1 = invalid-expression "pkg/front_end/testcases/nnbd/switch_nullable_enum.dart:7:5: Error: A non-null value must be returned since the return type 'int' doesn't allow null.
|
|
int method1(Enum? e) {
|
|
^" in null;
|
|
}
|
|
static method method2(self::Enum? e) → core::int {
|
|
switch(e) {
|
|
#L2:
|
|
case #C3:
|
|
case #C6:
|
|
{
|
|
return 0;
|
|
}
|
|
#L3:
|
|
case #C8:
|
|
{
|
|
return 1;
|
|
}
|
|
#L4:
|
|
default:
|
|
throw new _in::ReachabilityError::•("`null` encountered as case in a switch expression with a non-nullable enum type.");
|
|
}
|
|
}
|
|
static method method3(self::Enum? e) → core::int {
|
|
switch(e) {
|
|
#L5:
|
|
case #C3:
|
|
case #C6:
|
|
{
|
|
return 0;
|
|
}
|
|
#L6:
|
|
default:
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
static method method4(self::Enum? e) → core::int {
|
|
switch(e) {
|
|
#L7:
|
|
case #C3:
|
|
case #C6:
|
|
{
|
|
return 0;
|
|
}
|
|
#L8:
|
|
case #C8:
|
|
default:
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
static method test() → dynamic {
|
|
self::method1(#C3);
|
|
}
|
|
static method main() → dynamic {
|
|
self::expect(0, self::method2(#C3));
|
|
self::expect(0, self::method2(#C6));
|
|
self::expect(1, self::method2(null));
|
|
self::expect(0, self::method3(#C3));
|
|
self::expect(0, self::method3(#C6));
|
|
self::expect(1, self::method3(null));
|
|
self::expect(0, self::method4(#C3));
|
|
self::expect(0, self::method4(#C6));
|
|
self::expect(1, self::method4(null));
|
|
}
|
|
static method expect(dynamic expected, dynamic actual) → dynamic {
|
|
if(!expected.{core::Object::==}(actual)) {
|
|
throw "Expected ${expected}, actual ${actual}.";
|
|
}
|
|
}
|
|
|
|
constants {
|
|
#C1 = 0
|
|
#C2 = "Enum.e1"
|
|
#C3 = self::Enum {index:#C1, _name:#C2}
|
|
#C4 = 1
|
|
#C5 = "Enum.e2"
|
|
#C6 = self::Enum {index:#C4, _name:#C5}
|
|
#C7 = <self::Enum*>[#C3, #C6]
|
|
#C8 = null
|
|
}
|
|
|
|
|
|
Constructor coverage from constants:
|
|
org-dartlang-testcase:///switch_nullable_enum.dart:
|
|
- Enum. (from org-dartlang-testcase:///switch_nullable_enum.dart:5:6)
|
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
|