-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stable] [_fe_analyzer_shared] Handle private names in exhaustiveness…
… checking Closes #52041 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/297462 Change-Id: I2bc2fc8fb38b30eb5e9c6e639c2603a5508dfec1 Fixes: #52254 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302845 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]>
- Loading branch information
1 parent
7498681
commit 66fe70a
Showing
16 changed files
with
335 additions
and
18 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
pkg/_fe_analyzer_shared/test/exhaustiveness/data/issue52041.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,28 @@ | ||
// 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. | ||
|
||
sealed class B {} | ||
|
||
class C extends B { | ||
final int _i; | ||
|
||
C(this._i); | ||
} | ||
|
||
f(B b) { | ||
/* | ||
checkingOrder={B,C}, | ||
fields={_i:-}, | ||
subtypes={C}, | ||
type=B | ||
*/ | ||
switch (b) { | ||
/*space=C(_i: int)*/ case C(:var _i): | ||
print('C($_i)'); | ||
} | ||
} | ||
|
||
main() { | ||
f(C(0)); | ||
} |
40 changes: 40 additions & 0 deletions
40
pkg/_fe_analyzer_shared/test/exhaustiveness/data/private/main.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,40 @@ | ||
// 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. | ||
|
||
import 'main_lib.dart'; | ||
|
||
class A { | ||
num get _a => 42 | ||
int get _b => 42; | ||
} | ||
|
||
class C extends B { | ||
} | ||
|
||
exhaustiveA(A a) => /* | ||
fields={_a:num}, | ||
type=A | ||
*/switch (a) { A(: num _a) /*space=A(_a: num)*/=> 0, } | ||
|
||
nonExhaustiveA(A a) => /* | ||
error=non-exhaustive:A(_a: double()), | ||
fields={_a:num}, | ||
type=A | ||
*/switch (a) { A(: int _a) /*space=A(_a: int)*/=> 0, } | ||
|
||
exhaustiveB(B b) => /* | ||
fields={_b:int}, | ||
type=B | ||
*/switch (b) { B(: int _b) /*space=B(_b: int)*/=> 0, } | ||
|
||
exhaustiveC(C c) => /* | ||
fields={_a:num}, | ||
type=C | ||
*/switch (c) { C(: num _a) /*space=C(_a: num)*/=> 0, } | ||
|
||
nonExhaustiveA(C c) => /*analyzer. | ||
error=non-exhaustive:C(_a: double()), | ||
fields={_a:num}, | ||
type=C | ||
*/switch (c) { C(: int _a) /*analyzer.space=C(_a: int)*/=> 0, } |
10 changes: 10 additions & 0 deletions
10
pkg/_fe_analyzer_shared/test/exhaustiveness/data/private/main_lib.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,10 @@ | ||
// 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. | ||
|
||
import 'main.dart'; | ||
|
||
class B extends A { | ||
int get _a => 42; | ||
num get _b => 42; | ||
} |
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
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
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
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
22 changes: 22 additions & 0 deletions
22
pkg/front_end/testcases/patterns/exhaustiveness/issue52041.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,22 @@ | ||
// 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. | ||
|
||
sealed class B {} | ||
|
||
class C extends B { | ||
final int _i; | ||
|
||
C(this._i); | ||
} | ||
|
||
f(B b) { | ||
switch (b) { | ||
case C(:var _i): | ||
print('C($_i)'); | ||
} | ||
} | ||
|
||
main() { | ||
f(C(0)); | ||
} |
32 changes: 32 additions & 0 deletions
32
pkg/front_end/testcases/patterns/exhaustiveness/issue52041.dart.strong.expect
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,32 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
abstract sealed class B extends core::Object { | ||
synthetic constructor •() → self::B | ||
: super core::Object::•() | ||
; | ||
} | ||
class C extends self::B { | ||
final field core::int _i; | ||
constructor •(core::int _i) → self::C | ||
: self::C::_i = _i, super self::B::•() | ||
; | ||
} | ||
static method f(self::B b) → dynamic { | ||
#L1: | ||
{ | ||
final synthesized self::B #0#0 = b; | ||
{ | ||
hoisted core::int _i; | ||
if(#0#0 is{ForNonNullableByDefault} self::C && (let final dynamic #t1 = _i = #0#0{self::C}.{self::C::_i}{core::int} in true)) { | ||
{ | ||
core::print("C(${_i})"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
static method main() → dynamic { | ||
self::f(new self::C::•(0)); | ||
} |
32 changes: 32 additions & 0 deletions
32
pkg/front_end/testcases/patterns/exhaustiveness/issue52041.dart.strong.transformed.expect
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,32 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
abstract sealed class B extends core::Object { | ||
synthetic constructor •() → self::B | ||
: super core::Object::•() | ||
; | ||
} | ||
class C extends self::B { | ||
final field core::int _i; | ||
constructor •(core::int _i) → self::C | ||
: self::C::_i = _i, super self::B::•() | ||
; | ||
} | ||
static method f(self::B b) → dynamic { | ||
#L1: | ||
{ | ||
final synthesized self::B #0#0 = b; | ||
{ | ||
hoisted core::int _i; | ||
if(#0#0 is{ForNonNullableByDefault} self::C && (let final core::int #t1 = _i = #0#0{self::C}.{self::C::_i}{core::int} in true)) { | ||
{ | ||
core::print("C(${_i})"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
static method main() → dynamic { | ||
self::f(new self::C::•(0)); | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/front_end/testcases/patterns/exhaustiveness/issue52041.dart.textual_outline.expect
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,9 @@ | ||
sealed class B {} | ||
|
||
class C extends B { | ||
final int _i; | ||
C(this._i); | ||
} | ||
|
||
f(B b) {} | ||
main() {} |
9 changes: 9 additions & 0 deletions
9
...ont_end/testcases/patterns/exhaustiveness/issue52041.dart.textual_outline_modelled.expect
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,9 @@ | ||
class C extends B { | ||
C(this._i); | ||
final int _i; | ||
} | ||
|
||
f(B b) {} | ||
main() {} | ||
|
||
sealed class B {} |
35 changes: 35 additions & 0 deletions
35
pkg/front_end/testcases/patterns/exhaustiveness/issue52041.dart.weak.expect
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,35 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "dart:_internal" as _in; | ||
|
||
abstract sealed class B extends core::Object { | ||
synthetic constructor •() → self::B | ||
: super core::Object::•() | ||
; | ||
} | ||
class C extends self::B { | ||
final field core::int _i; | ||
constructor •(core::int _i) → self::C | ||
: self::C::_i = _i, super self::B::•() | ||
; | ||
} | ||
static method f(self::B b) → dynamic { | ||
#L1: | ||
{ | ||
final synthesized self::B #0#0 = b; | ||
{ | ||
hoisted core::int _i; | ||
if(#0#0 is{ForNonNullableByDefault} self::C && (let final dynamic #t1 = _i = #0#0{self::C}.{self::C::_i}{core::int} in true)) { | ||
{ | ||
core::print("C(${_i})"); | ||
} | ||
} | ||
break #L1; | ||
} | ||
throw new _in::ReachabilityError::•("`null` encountered as case in a switch statement with a non-nullable type."); | ||
} | ||
} | ||
static method main() → dynamic { | ||
self::f(new self::C::•(0)); | ||
} |
Oops, something went wrong.