Closed
Description
The following test works in CFE but fails in analyzer
// SharedOptions=--enable-experiment=inline-class
import "../../Utils/expect.dart";
enum E {
a, b, c
}
extension type ET1(E _) {}
extension type ET2(E _) implements E {}
String testStatement1(ET1 e) { // COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY The body might complete normally, causing 'null' to be returned, but the return type, 'String', is a potentially non-nullable type.
switch (e) {
case E.a:
case E.b:
case E.c:
return "ok";
}
}
String testStatement2(ET2 e) { // COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY The body might complete normally, causing 'null' to be returned, but the return type, 'String', is a potentially non-nullable type.
switch (e) {
case E.a:
case E.b:
return "ok1";
case E.c:
return "ok2";
}
}
String testExpression1(ET1 e) => // Ok, works
switch (e) {
E.a => "a",
E.b => "b",
E.c => "c"
};
String testExpression2(ET2 e) => // Ok, works
switch (e) {
E.a => "a",
E.b => "b",
E.c => "c"
};
main() {
Expect.equals("ok", testStatement1(ET1(E.a)));
Expect.equals("ok", testStatement1(ET1(E.b)));
Expect.equals("ok", testStatement1(ET1(E.c)));
Expect.equals("a", testExpression1(ET1(E.a)));
Expect.equals("a", testExpression1(ET1(E.b)));
Expect.equals("c", testExpression1(ET1(E.c)));
Expect.equals("ok1", testStatement2(ET2(E.a)));
Expect.equals("ok1", testStatement2(ET2(E.b)));
Expect.equals("ok2", testStatement2(ET2(E.c)));
Expect.equals("a", testExpression2(ET2(E.a)));
Expect.equals("b", testExpression2(ET2(E.b)));
Expect.equals("c", testExpression2(ET2(E.c)));
}
co19 tests that fails
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t01
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t02
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t03
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t04
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t05