forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2145. Update variables tests according to the current spec.…
… Part 2
- Loading branch information
Showing
31 changed files
with
691 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
Language/Variables/Implicitly_Induced_Getters_and_Setters/definition_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 Case ⟨Getter: Variable with declared type ⟩. Consider a variable | ||
/// declaration of one of the forms | ||
/// • static? late? final? T id; | ||
/// • static? late? final? T id = e; | ||
/// • static? const T id = e; | ||
/// where T is a type, id is an identifier, and ‘?’ indicates that the given | ||
/// modifier may be present or absent. Each of these declarations implicitly | ||
/// induces a getter with the header T get id. | ||
/// ... | ||
/// In these cases the declared type of id is T. | ||
/// | ||
/// @description Checks that the static type of an implicit getter is its | ||
/// declared type | ||
/// @author sgrekhov22@gmail.com | ||
import "../../../Utils/static_type_helper.dart"; | ||
|
||
late final int? x1; | ||
late int x2; | ||
int? x3; | ||
late final int x4 = 4; | ||
late int x5 = 5; | ||
final int x6 = 6; | ||
int x7 = 7; | ||
const int x8 = 8; | ||
|
||
class C { | ||
static late final int v11; | ||
static late int v12; | ||
late int v13; | ||
int? v14; | ||
late final int v15; | ||
late int v16; | ||
|
||
static late final int v21 = 21; | ||
static late int v22 = 22; | ||
static int v23 = 23; | ||
static final int v24 = 24; | ||
late final int v25 = 25; | ||
late int v26 = 26; | ||
final int v27 = 27; | ||
int v28 = 28; | ||
|
||
static const int v31 = 31; | ||
} | ||
|
||
main() { | ||
x1 = 1 as dynamic; | ||
x1.expectStaticType<Exactly<int?>>(); | ||
x2.expectStaticType<Exactly<int>>(); | ||
x3.expectStaticType<Exactly<int?>>(); | ||
x4.expectStaticType<Exactly<int>>(); | ||
x5.expectStaticType<Exactly<int>>(); | ||
x6.expectStaticType<Exactly<int>>(); | ||
|
||
C c = C(); | ||
C.v11 = 11 as dynamic; | ||
C.v12 = 12 as dynamic; | ||
c.v13 = 13 as dynamic; | ||
c.v14 = 14 as dynamic; | ||
c.v15 = 15 as dynamic; | ||
c.v16 = 16 as dynamic; | ||
C.v11.expectStaticType<Exactly<int>>(); | ||
C.v12.expectStaticType<Exactly<int>>(); | ||
c.v13.expectStaticType<Exactly<int>>(); | ||
c.v14.expectStaticType<Exactly<int?>>(); | ||
c.v15.expectStaticType<Exactly<int>>(); | ||
c.v16.expectStaticType<Exactly<int>>(); | ||
C.v21.expectStaticType<Exactly<int>>(); | ||
C.v22.expectStaticType<Exactly<int>>(); | ||
C.v23.expectStaticType<Exactly<int>>(); | ||
C.v24.expectStaticType<Exactly<int>>(); | ||
c.v25.expectStaticType<Exactly<int>>(); | ||
c.v26.expectStaticType<Exactly<int>>(); | ||
c.v27.expectStaticType<Exactly<int>>(); | ||
c.v28.expectStaticType<Exactly<int>>(); | ||
C.v31.expectStaticType<Exactly<int>>(); | ||
} |
103 changes: 103 additions & 0 deletions
103
Language/Variables/Implicitly_Induced_Getters_and_Setters/definition_A02_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// 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 Case ⟨Getter: Variable with no declared type ⟩. A variable | ||
/// declaration of one of the forms | ||
/// • static? late? var id; | ||
/// • static? late? var id = e; | ||
/// • static? late? final id; | ||
/// • static? late? final id = e; | ||
/// • static? const id = e; | ||
/// implicitly induces a getter with the header that contains static iff the | ||
/// declaration contains static and is followed by T get id, where T is obtained | ||
/// from type inference in the case where e exists, and T is dynamic otherwise. | ||
/// ... | ||
/// In these cases, the declared type of id is T | ||
/// | ||
/// @description Checks the static type of an implicit getter of a variable with | ||
/// no declared type | ||
/// @author sgrekhov22@gmail.com | ||
import "../../../Utils/static_type_helper.dart"; | ||
|
||
late var x1; | ||
var x2; | ||
late var x3 = 3; | ||
var x4 = 4; | ||
|
||
late final x5; | ||
late final x6 = 6; | ||
final x7 = 7; | ||
|
||
const x8 = 8; | ||
|
||
class C { | ||
static late var v1; | ||
late var v2; | ||
var v3; | ||
static var v4; | ||
|
||
static late var v5 = 5; | ||
static var v6 = 6; | ||
late var v7 = 7; | ||
var v8 = 8; | ||
|
||
static late final v10; | ||
late final v11; | ||
|
||
static late final v12 = 12; | ||
static final v13 = 13; | ||
late final v14 = 14; | ||
final v15 = 15; | ||
|
||
static const v20 = 20; | ||
} | ||
|
||
main() { | ||
try { | ||
x1.whatever; | ||
} catch (_) {} | ||
try { | ||
x2.whatever; | ||
} catch (_) {} | ||
x3.expectStaticType<Exactly<int>>(); | ||
x4.expectStaticType<Exactly<int>>(); | ||
|
||
try { | ||
x5.whatever; | ||
} catch (_) {} | ||
x6.expectStaticType<Exactly<int>>(); | ||
x7.expectStaticType<Exactly<int>>(); | ||
x8.expectStaticType<Exactly<int>>(); | ||
|
||
C c = C(); | ||
try { | ||
C.v1.whatever; | ||
} catch (_) {} | ||
try { | ||
c.v2.whatever; | ||
} catch (_) {} | ||
try { | ||
c.v3.whatever; | ||
} catch (_) {} | ||
try { | ||
C.v4.whatever; | ||
} catch (_) {} | ||
C.v5.expectStaticType<Exactly<int>>(); | ||
C.v6.expectStaticType<Exactly<int>>(); | ||
c.v7.expectStaticType<Exactly<int>>(); | ||
c.v8.expectStaticType<Exactly<int>>(); | ||
|
||
try { | ||
C.v10.whatever; | ||
} catch (_) {} | ||
try { | ||
c.v11.whatever; | ||
} catch (_) {} | ||
C.v12.expectStaticType<Exactly<int>>(); | ||
C.v13.expectStaticType<Exactly<int>>(); | ||
c.v14.expectStaticType<Exactly<int>>(); | ||
c.v15.expectStaticType<Exactly<int>>(); | ||
C.v20.expectStaticType<Exactly<int>>(); | ||
} |
48 changes: 48 additions & 0 deletions
48
Language/Variables/Implicitly_Induced_Getters_and_Setters/definition_A03_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 Case ⟨Setter: Mutable variable with declared type ⟩. A variable | ||
/// declaration of one of the forms | ||
/// • static? late? T id; | ||
/// • static? late? T id = e; | ||
/// implicitly induces a setter with the header void set id(T x), whose | ||
/// execution sets the value of id to the incoming argument x. | ||
/// | ||
/// @description Checks the static type of an implicit getter of a variable with | ||
/// no declared type | ||
/// @author sgrekhov22@gmail.com | ||
late int x1; | ||
int? x2; | ||
int x3 = 3; | ||
late int x4 = 4; | ||
|
||
class C { | ||
static late int v1; | ||
late int v2; | ||
int? v3; | ||
static int? v4; | ||
|
||
static late int v5 = 5; | ||
static int v6 = 6; | ||
late int v7 = 7; | ||
int v8 = 8; | ||
} | ||
|
||
main() { | ||
x1 = -1; | ||
x2 = -2; | ||
x3 = -3; | ||
x4 = -4; | ||
|
||
C c = C(); | ||
C.v1 = -1; | ||
c.v2 = -2; | ||
c.v3 = -3; | ||
C.v4 = -4; | ||
C.v5 = -5; | ||
C.v6 = -6; | ||
c.v7 = -7; | ||
c.v8 = -8; | ||
} |
54 changes: 54 additions & 0 deletions
54
Language/Variables/Implicitly_Induced_Getters_and_Setters/definition_A04_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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 Case ⟨Setter: Mutable variable with no declared type, with | ||
/// initialization⟩. | ||
/// A variable declaration of the form static? late? var id = e; implicitly | ||
/// induces a setter with the header void set id(dynamic x), whose execution | ||
/// sets the value of id to the incoming argument x. | ||
/// Type inference could have provided a type different from dynamic. | ||
/// | ||
/// @description Checks that the static type of an implicit getter of a mutable | ||
/// variable with no declared type but with an initialization is provided by the | ||
/// type inference | ||
/// @author sgrekhov22@gmail.com | ||
late var x1 = 1; | ||
var x2 = 2; | ||
|
||
class C { | ||
static late var v1 = 1; | ||
late var v2 = 2; | ||
var v3 = 3; | ||
static var v4 = 4; | ||
} | ||
|
||
main() { | ||
x1 = -1; | ||
x2 = -2; | ||
try { | ||
x1 = "1" as dynamic; | ||
} catch (_) {} | ||
try { | ||
x2 = "2" as dynamic; | ||
} catch (_) {} | ||
|
||
C c = C(); | ||
C.v1 = -1; | ||
c.v2 = -2; | ||
c.v3 = -3; | ||
C.v4 = -4; | ||
try { | ||
C.v1 = "1" as dynamic; | ||
} catch (_) {} | ||
try { | ||
c.v2 = "2" as dynamic; | ||
} catch (_) {} | ||
try { | ||
c.v3 = "3" as dynamic; | ||
} catch (_) {} | ||
try { | ||
C.v4 = "4" as dynamic; | ||
} catch (_) {} | ||
} |
39 changes: 39 additions & 0 deletions
39
Language/Variables/Implicitly_Induced_Getters_and_Setters/definition_A05_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 Case ⟨Setter: Mutable variable with no declared type, no | ||
/// initialization⟩. A variable declaration of the form static? late? var id; | ||
/// implicitly induces a setter with the header void set id(dynamic x), whose | ||
/// execution sets the value of id to the incoming argument x. | ||
/// | ||
/// @description Checks that the static type of an implicit getter of a mutable | ||
/// variable with no declared type and no initialization is `dynamic` | ||
/// @author sgrekhov22@gmail.com | ||
late var x1; | ||
var x2; | ||
|
||
class C { | ||
static late var v1; | ||
late var v2; | ||
var v3; | ||
static var v4; | ||
} | ||
|
||
main() { | ||
x1 = -1; | ||
x1 = "1"; | ||
x2 = 2; | ||
x2 = "2"; | ||
|
||
C c = C(); | ||
C.v1 = 1; | ||
C.v1 = "1"; | ||
c.v2 = 2; | ||
c.v2 = "2"; | ||
c.v3 = 3; | ||
c.v3 = "3"; | ||
C.v4 = 4; | ||
C.v4 = "4"; | ||
} |
34 changes: 34 additions & 0 deletions
34
Language/Variables/Implicitly_Induced_Getters_and_Setters/definition_A06_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 Case ⟨Setter: Late-final variable with declared type ⟩. A | ||
/// variable declaration of the form static? late final T id; implicitly induces | ||
/// a setter with the header void set id(T x). If this setter is executed in a | ||
/// situation where the variable id has not been bound, it will bind id to the | ||
/// object that x is bound to. If this setter is executed in a situation where | ||
/// the variable id has been bound to an object, a dynamic error occurs | ||
/// | ||
/// @description Checks the static type of an implicit getter of a late final | ||
/// variable with declared type | ||
/// @author sgrekhov22@gmail.com | ||
import "../../../Utils/static_type_helper.dart"; | ||
|
||
late final int x1; | ||
|
||
class C { | ||
static late final int v1; | ||
late final int v2; | ||
} | ||
|
||
main() { | ||
x1 = 1; | ||
x1.expectStaticType<Exactly<int>>(); | ||
|
||
C c = C(); | ||
C.v1 = 1; | ||
C.v1.expectStaticType<Exactly<int>>(); | ||
c.v2 = 2; | ||
c.v2.expectStaticType<Exactly<int>>(); | ||
} |
Oops, something went wrong.