Skip to content

Commit

Permalink
#2145. Update variables tests according to the current spec. Part 2 (#…
Browse files Browse the repository at this point in the history
…2240)

Update variable tests according to the current spec. Part 2
  • Loading branch information
sgrekhov committed Sep 1, 2023
1 parent 656e653 commit ace9354
Show file tree
Hide file tree
Showing 35 changed files with 951 additions and 326 deletions.
23 changes: 23 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is not an error if a local variable is final and
/// not initialized at its point of declaration.
/// @author ilya
main() {
final i;
i = 1;
}
26 changes: 26 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is not an error if a local variable is final and
/// not initialized at its point of declaration.
/// @author ilya
main() {
f() {
final i;
return i = 1;
}
f();
}
25 changes: 25 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is not an error if a local variable is final
/// and not initialized at its point of declaration.
/// @author ilya
main() {
() {
final i;
return i = 1;
} ();
}
29 changes: 29 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is not an error if a local variable is final and
/// not initialized at its point of declaration.
/// @author ilya
class C {
f() {
final i;
return i = 1;
}
}

main() {
new C().f();
}
26 changes: 26 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is a compile-time error to read a local
/// definitely unassigned final variable.
/// @author ilya
main() {
final i;
var j = i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
29 changes: 29 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is a compile-time error to read a local
/// definitely unassigned final variable.
/// @author ilya
main() {
f() {
final i;
return i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
f();
}
28 changes: 28 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A02_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2011, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is a compile-time error to read a local
/// definitely unassigned final variable.
/// @author ilya
main() {
() {
final i;
return i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
} ();
}
33 changes: 33 additions & 0 deletions Language/Statements/Local_Variable_Declaration/final_A02_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2020, 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 If a local variable v is final and not late, it is not a
/// compile-time error if the declaration of v is not an initializing variable
/// declaration, but an expression that gives rise to evaluation of v is a
/// compile-time error unless flow analysis shows that the variable is
/// guaranteed to have been initialized. Similarly, an expression that gives
/// rise to an assignment to v is a compile-time error unless flow analysis
/// shows that it is guaranteed that the variable has not been initialized.
///
/// In every situation which is not covered by the previous paragraph, it is a
/// compile-time error to assign to a local variable which is final and not late
///
/// @description Checks that it is a compile-time error to read a local
/// definitely unassigned final variable.
/// @author iarkh@unipro.ru
/// @author sgrekhov@unipro.ru
class C {
f() {
final i;
return i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
}

main() {
new C().f();
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class C {

main() {
Expect.equals(4, C.d);
Expect.equals("4", log, "Lazy static getters execution was wrong!");
Expect.equals(1, C.a);
Expect.equals("41", log, "Lazy static getters execution was wrong!");
Expect.equals(2, C.b);
Expect.equals("412", log, "Lazy static getters execution was wrong!");
Expect.equals(3, C.c);

Expect.equals("4123", log, "Lazy static getters execution was wrong!");
}
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>>();
}

0 comments on commit ace9354

Please sign in to comment.