blob: c152a0bcff12eca22b64704197bb1c902bdc0245 [file] [log] [blame]
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;
class Enum extends core::_Enum /*isEnum*/ {
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
: super core::_Enum::•(index, name)
;
method toString() core::String
return "Enum.${this.{core::_Enum::_name}{core::String}}";
}
static method method1(self::Enum? e) core::int {
switch(e) {
#L1:
case #C3:
case #C6:
{
return 0;
}
}
return 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;
}
}
}
static method method3(self::Enum? e) core::int {
switch(e) {
#L4:
case #C3:
case #C6:
{
return 0;
}
#L5:
default:
{
return 1;
}
}
}
static method method4(self::Enum? e) core::int {
switch(e) {
#L6:
case #C3:
case #C6:
{
return 0;
}
#L7:
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:5:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart:76:9)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)