mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 16:19:07 +00:00
[dart2js] Repro for issue 52170.
Type inference is not tracking the type of 'local' correctly through the switch statement into the inner return. The same code without the for loop does work correctly though. Change-Id: I0b1b4741e4ff17c22dec3383defb412f5fff0836 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298980 Reviewed-by: Stephen Adams <sra@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
This commit is contained in:
parent
a7854364a6
commit
a6f543e50a
32
pkg/compiler/test/inference/data/issue_52170.dart
Normal file
32
pkg/compiler/test/inference/data/issue_52170.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
// 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.
|
||||
|
||||
/*member: getInt:[exact=JSUInt31]*/
|
||||
int get getInt => 42;
|
||||
|
||||
// TODO(http://dartbug.com/52170): Return type should include int. The return
|
||||
// within the loop can and will be invoked with local = 3.
|
||||
/*member: foo:Value([null|exact=JSString], value: "hello")*/
|
||||
foo() {
|
||||
dynamic local = 3;
|
||||
for (int i = 0;
|
||||
i /*invoke: [subclass=JSPositiveInt]*/ < 10;
|
||||
i /*invoke: [subclass=JSPositiveInt]*/ ++) {
|
||||
switch (getInt) {
|
||||
case 42:
|
||||
break;
|
||||
default:
|
||||
local = 'hello';
|
||||
}
|
||||
if (i /*invoke: [subclass=JSPositiveInt]*/ > 5) {
|
||||
return local;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: main:[null]*/
|
||||
void main() {
|
||||
foo();
|
||||
}
|
Loading…
Reference in a new issue