54b588a373
Closes #53615 TEST=existing Change-Id: Ic2ad21787e62c8051dc2020cc15d61195f512b80 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330440 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
122 lines
3.0 KiB
Plaintext
122 lines
3.0 KiB
Plaintext
library;
|
|
//
|
|
// Problems in library:
|
|
//
|
|
// pkg/front_end/testcases/nnbd/switch_nullable_enum.dart:9: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::_Enum /*isEnum*/ {
|
|
static const field core::List<self::Enum> values = #C7;
|
|
enum-element static const field self::Enum e1 = #C3;
|
|
enum-element static const field self::Enum e2 = #C6;
|
|
const synthetic constructor •(core::int #index, core::String #name) → self::Enum
|
|
: super core::_Enum::•(#index, #name)
|
|
;
|
|
method _enumToString() → core::String
|
|
return "Enum.${this.{core::_Enum::_name}{core::String}}";
|
|
}
|
|
static method method1(self::Enum? e) → core::int {
|
|
switch(e) /* self::Enum? */ {
|
|
#L1:
|
|
case #C3:
|
|
case #C6:
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
return invalid-expression "pkg/front_end/testcases/nnbd/switch_nullable_enum.dart:9: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) /* isExplicitlyExhaustive, self::Enum? */ {
|
|
#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) /* self::Enum? */ {
|
|
#L5:
|
|
case #C3:
|
|
case #C6:
|
|
{
|
|
return 0;
|
|
}
|
|
#L6:
|
|
default:
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
static method method4(self::Enum? e) → core::int {
|
|
switch(e) /* self::Enum? */ {
|
|
#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::==}{(core::Object) → core::bool} actual)) {
|
|
throw "Expected ${expected}, actual ${actual}.";
|
|
}
|
|
}
|
|
|
|
constants {
|
|
#C1 = 0
|
|
#C2 = "e1"
|
|
#C3 = self::Enum {index:#C1, _name:#C2}
|
|
#C4 = 1
|
|
#C5 = "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:7:6)
|
|
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart)
|
|
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart)
|