diff --git a/Language/Classes/Constructors/Factories/redirecting_constructor_t06.dart b/Language/Classes/Constructors/Factories/redirecting_constructor_t06.dart index 931df302c9..e7fcb7ddd1 100644 --- a/Language/Classes/Constructors/Factories/redirecting_constructor_t06.dart +++ b/Language/Classes/Constructors/Factories/redirecting_constructor_t06.dart @@ -17,22 +17,20 @@ /// @author sgrekhov22@gmail.com class F { - external factory F(num x) = C; -// ^ + external factory F() = C; +// ^ // [analyzer] unspecified // [cfe] unspecified - external factory F.f1(num x) = C.f1; -// ^ + external factory F.f1() = C.f1; +// ^ // [analyzer] unspecified // [cfe] unspecified } class C implements F { - num x; - - external C(this.x); - C.f1(this.x); + external C(); + C.f1(); } enum E { diff --git a/Language/Classes/Constructors/Factories/return_type_A03_t02.dart b/Language/Classes/Constructors/Factories/return_type_A03_t02.dart index b940044c16..0d5f0ac6c8 100644 --- a/Language/Classes/Constructors/Factories/return_type_A03_t02.dart +++ b/Language/Classes/Constructors/Factories/return_type_A03_t02.dart @@ -9,6 +9,8 @@ /// null object. /// @author sgrekhov22@gmail.com +// Requirements=nnbd-strong + import "../../../../Utils/expect.dart"; class C { diff --git a/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t04.dart b/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t04.dart index 07424aafe0..957918f03b 100644 --- a/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t04.dart +++ b/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t04.dart @@ -47,7 +47,7 @@ String testExpression1(ET1 e) => E.c => "c" }; -String testExpression2(ET2 e) => +String testExpression2(ET2 e) => switch (e) { E.a => "a", E.b => "b", diff --git a/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t01.dart b/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t01.dart index fc935304ea..2afe767a48 100644 --- a/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t01.dart +++ b/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t01.dart @@ -22,9 +22,10 @@ extension type ET1(E _) {} extension type ET2(E _) implements E {} String testStatement1(ET1 e) { +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified switch (e) { //^^^^^^ -// [analyzer] unspecified // [cfe] unspecified case E.a: return "a"; @@ -34,9 +35,10 @@ String testStatement1(ET1 e) { } String testStatement2(ET2 e) { +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified switch (e) { //^^^^^^ -// [analyzer] unspecified // [cfe] unspecified case E.a: return "a"; @@ -64,9 +66,10 @@ String testExpression2(ET2 e) => }; String testStatement3(ET1 e) { +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified switch (e) { //^^^^^^ -// [analyzer] unspecified // [cfe] unspecified case E.a: return "ok"; @@ -74,9 +77,10 @@ String testStatement3(ET1 e) { } String testStatement4(ET2 e) { +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified switch (e) { //^^^^^^ -// [analyzer] unspecified // [cfe] unspecified case E.a: return "ok"; diff --git a/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t02.dart b/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t02.dart index 013719c260..4b0cd28692 100644 --- a/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t02.dart +++ b/LanguageFeatures/Extension-types/exhaustiveness_enum_A02_t02.dart @@ -20,9 +20,10 @@ extension type ET1(E _) {} extension type ET2(E _) implements E {} String testStatement1(ET1 e) { +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified switch (e) { //^^^^^^ -// [analyzer] unspecified // [cfe] unspecified case E.a: return "a"; @@ -32,9 +33,10 @@ String testStatement1(ET1 e) { } String testStatement2(ET2 e) { +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified switch (e) { //^^^^^^ -// [analyzer] unspecified // [cfe] unspecified case E.a: return "a"; diff --git a/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t01.dart b/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t01.dart index 7229002dad..d91a35583f 100644 --- a/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t01.dart +++ b/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t01.dart @@ -35,21 +35,6 @@ String test1_2(ET2 m) => Map() => "other" }; -String test2_1(ET1 m) { - switch (m) { - case {true: true}: - return "case-1"; - case {true: false}: - return "case-2"; - case {false: true}: - return "case-3"; - case {false: false}: - return "case-4"; - case Map(): - return "other"; - } -} - String test2_2(ET2 m) { switch (m) { case {true: true}: @@ -68,14 +53,11 @@ String test2_2(ET2 m) { main() { Expect.equals("case-1", test1_1(ET1({true: true}))); Expect.equals("case-2", test1_2(ET2({true: false}))); - Expect.equals("case-3", test2_1(ET1({false: true}))); Expect.equals("case-4", test2_2(ET2({false: false}))); Expect.equals("other", test1_1(ET1({}))); Expect.equals("other", test1_2(ET2({}))); - Expect.equals("other", test2_1(ET1({}))); Expect.equals("other", test2_2(ET2({}))); - Expect.equals("other", test1_1(ET1({true: true, false: false}))); - Expect.equals("other", test1_2(ET2({true: false, false: false}))); - Expect.equals("other", test2_1(ET1({false: true, true: true}))); - Expect.equals("other", test2_2(ET2({false: false, true: true}))); + Expect.equals("case-1", test1_1(ET1({true: true, false: false}))); + Expect.equals("case-2", test1_2(ET2({true: false, false: false}))); + Expect.equals("case-1", test2_2(ET2({false: false, true: true}))); } diff --git a/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t02.dart b/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t02.dart new file mode 100644 index 0000000000..c2a46c07db --- /dev/null +++ b/LanguageFeatures/Extension-types/exhaustiveness_map_A02_t02.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Exhaustiveness with map patterns can only be achieved when there +/// is an exhaustive pattern in addition to any map patterns +/// +/// @description Check that a switch statement with a value type an extension +/// type with a `Map` as a representation type but which doesn't implement `Map` +/// is not exhaustive +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +extension type ET1(Map _) {} + +String test(ET1 m) { +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + switch (m) { + case {true: true}: + return "case-1"; + case {true: false}: + return "case-2"; + case {false: true}: + return "case-3"; + case {false: false}: + return "case-4"; + case Map(): + return "other"; + } +} + +main() { + test(ET1({false: true})); +} diff --git a/LanguageFeatures/Patterns/Exhaustiveness/exhaustiveness_map_A02_t01.dart b/LanguageFeatures/Patterns/Exhaustiveness/exhaustiveness_map_A02_t01.dart new file mode 100644 index 0000000000..4a17db588b --- /dev/null +++ b/LanguageFeatures/Patterns/Exhaustiveness/exhaustiveness_map_A02_t01.dart @@ -0,0 +1,71 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Exhaustiveness with map patterns can only be achieved when there +/// is an exhaustive pattern in addition to any map patterns +/// +/// @description Check that a switch statement/expression with map patterns and +/// additional exhaustive pattern can be exhaustive. +/// @author sgrekhov22@gmail.com + +import "../../../Utils/expect.dart"; + +String test1_1(Map m) => + switch (m) { + {true: true} => "case-1", + {true: false} => "case-2", + {false: true} => "case-3", + {false: false} => "case-4", + Map() => "other" + }; + +String test1_2(Map m) => + switch (m) { + {true: true} => "case-1", + {true: false} => "case-2", + {false: true} => "case-3", + {false: false} => "case-4", + Map() => "other" + }; + +String test2_1(Map m) { + switch (m) { + case {true: true}: + return "case-1"; + case {true: false}: + return "case-2"; + case {false: true}: + return "case-3"; + case {false: false}: + return "case-4"; + case Map(): + return "other"; + } +} + +String test2_2(Map m) { + switch (m) { + case {true: true}: + return "case-1"; + case {true: false}: + return "case-2"; + case {false: true}: + return "case-3"; + case {false: false}: + return "case-4"; + case Map(): + return "other"; + } +} + +main() { + Expect.equals("other", test1_1({})); + Expect.equals("other", test1_2({})); + Expect.equals("other", test2_1({})); + Expect.equals("other", test2_2({})); + Expect.equals("case-1", test1_1({true: true, false: false})); + Expect.equals("case-2", test1_2({true: false, false: false})); + Expect.equals("case-1", test2_1({false: true, true: true})); + Expect.equals("case-1", test2_2({false: false, true: true})); +}