-
Notifications
You must be signed in to change notification settings - Fork 28
Fixes #1361. Private fields promotion tests added #1391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
LanguageFeatures/Private-fields-promotion/promotion_A01_t01.dart
This file contains hidden or 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) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable if all of the | ||
/// conditions above are met | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class C { | ||
final int? _x; | ||
final int? _y = 42; | ||
C(this._x); | ||
|
||
void test() { | ||
if (_x != null) { | ||
_x.isOdd; | ||
} | ||
if (_y != null) { | ||
_y.isOdd; | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
C(42).test(); | ||
} |
30 changes: 30 additions & 0 deletions
30
LanguageFeatures/Private-fields-promotion/promotion_A01_t02.dart
This file contains hidden or 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,30 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable if all of the | ||
/// conditions above are met. Test type variable | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class C<T> { | ||
final T _x; | ||
C(this._x); | ||
|
||
void test() { | ||
if (_x is int) { | ||
_x.isOdd; | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
C(42).test(); | ||
} |
35 changes: 35 additions & 0 deletions
35
LanguageFeatures/Private-fields-promotion/promotion_A01_t03.dart
This file contains hidden or 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,35 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable if all of the | ||
/// conditions above are met. Test type variable | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class A {} | ||
class B extends A { | ||
void foo() {} | ||
} | ||
|
||
class C<T extends A> { | ||
final T _x; | ||
C(this._x); | ||
|
||
void test() { | ||
if (_x is B) { | ||
_x.foo(); | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
C(B()).test(); | ||
} |
59 changes: 59 additions & 0 deletions
59
LanguageFeatures/Private-fields-promotion/promotion_A01_t04.dart
This file contains hidden or 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,59 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable if all of the | ||
/// conditions above are met. Test the case when there are other concrete | ||
/// instance getters with the same name in the same library and they are also | ||
/// final fields | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class A { | ||
final int? _x; | ||
A(this._x); | ||
|
||
void testA() { | ||
if (_x != null) { | ||
_x.isOdd; | ||
} | ||
} | ||
} | ||
|
||
class B { | ||
final String? _x; | ||
B(this._x); | ||
|
||
void testB() { | ||
if (_x != null) { | ||
_x.substring(0); | ||
} | ||
} | ||
} | ||
|
||
class C extends A { | ||
final int? _x; | ||
C(this._x) : super(_x); | ||
|
||
void testC() { | ||
if (_x != null) { | ||
_x.isOdd; | ||
} | ||
if (super._x != null) { | ||
super._x.isOdd; | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
A(42).testA(); | ||
B("X").testB(); | ||
C(1).testC(); | ||
} |
63 changes: 63 additions & 0 deletions
63
LanguageFeatures/Private-fields-promotion/promotion_A01_t05.dart
This file contains hidden or 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,63 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable if all of the | ||
/// conditions above are met. Test that the right variable is promoted | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class A { | ||
final int? _x; | ||
A(this._x); | ||
} | ||
|
||
class C extends A { | ||
final int? _x; | ||
C(this._x) : super(_x); | ||
|
||
void testC() { | ||
if (_x != null) { | ||
super._x.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
if (super._x != null) { | ||
_x.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
} | ||
|
||
mixin M on A { | ||
final int? _x = 0; | ||
|
||
void testM() { | ||
if (_x != null) { | ||
super._x.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
if (super._x != null) { | ||
_x.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
C(42).testC(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! |
27 changes: 27 additions & 0 deletions
27
LanguageFeatures/Private-fields-promotion/promotion_A02_t01.dart
This file contains hidden or 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,27 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable even if it is late | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class C { | ||
late final int? _x; | ||
|
||
void test() { | ||
_x = 42; | ||
_x.isOdd; | ||
} | ||
} | ||
|
||
main() { | ||
C().test(); | ||
} |
31 changes: 31 additions & 0 deletions
31
LanguageFeatures/Private-fields-promotion/promotion_A02_t02.dart
This file contains hidden or 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,31 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is promotable even if it is late | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class A { | ||
void foo() {} | ||
} | ||
|
||
class C<T extends A> { | ||
late final T? _x; | ||
|
||
void test(T t) { | ||
_x = t; | ||
_x.foo(); | ||
} | ||
} | ||
|
||
main() { | ||
C().test(A()); | ||
} |
40 changes: 40 additions & 0 deletions
40
LanguageFeatures/Private-fields-promotion/promotion_A03_t01.dart
This file contains hidden or 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,40 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is not promotable if it is not | ||
/// private | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class C { | ||
final int? x; | ||
final int? y = 42; | ||
C(this.x); | ||
|
||
void test() { | ||
if (x != null) { | ||
x.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
if (y != null) { | ||
y.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
C(42).test(); | ||
} |
33 changes: 33 additions & 0 deletions
33
LanguageFeatures/Private-fields-promotion/promotion_A03_t02.dart
This file contains hidden or 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,33 @@ | ||
// Copyright (c) 2022, 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 An instance field is promotable only if | ||
/// (a) it is private, | ||
/// (b) it is final, and | ||
/// (c) all other concrete instance getters with the same name in the same | ||
/// library are also final fields | ||
/// | ||
/// @description Checks that an instance field is not promotable if it is not | ||
/// private. Test type variable | ||
/// @author [email protected] | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
class C<T> { | ||
final T x; | ||
C(this.x); | ||
|
||
void test() { | ||
if (x is int) { | ||
x.isOdd; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
C(42).test(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, nice corner case! My current prototype code doesn't handle it properly. I'll make sure to fix it :)