-
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] [vm/aot/tfa] Fix handling of type parameter nullability in f…
…actory constructors TFA represents type parameters inside factory constructors as additional parameters. In a summary, type parameter type is represented simply as a reference to a parameter. This approach ignores nullability of a type parameter type, which is not correct. This change add a new ApplyNullability operation to a summary in order to apply any extra nullability ('?' or '*') on top of the type argument passed to a factory constructor. TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_50392_nnbd_strong.dart Fixes #50392 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/268381 Change-Id: I74080813663fbb7176ad30c0daf9f75de087506b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268500 Reviewed-by: Siva Annamalai <[email protected]>
- Loading branch information
1 parent
657d2c9
commit 203d14e
Showing
5 changed files
with
107 additions
and
18 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
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
23 changes: 23 additions & 0 deletions
23
pkg/vm/testcases/transformations/type_flow/transformer/regress_50392_nnbd_strong.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,23 @@ | ||
// 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. | ||
|
||
// Regression test for https://github.com/dart-lang/sdk/issues/50392 | ||
|
||
void main(List<String> arguments) { | ||
final model = Model(); | ||
|
||
print(model.value); // null | ||
print(model.value == null); // true | ||
} | ||
|
||
class Model<T extends num> { | ||
final T? value; | ||
|
||
Model._(this.value); | ||
|
||
factory Model() { | ||
Object? value = (int.parse('1') == 1) ? null : 42; | ||
return Model._(value as T?); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
pkg/vm/testcases/transformations/type_flow/transformer/regress_50392_nnbd_strong.dart.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,20 @@ | ||
library #lib /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "dart:_internal" as _in; | ||
|
||
class Model<T extends core::num> extends core::Object { | ||
[@vm.inferred-type.metadata=dart.core::_Smi?] [@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasNonThisUses:false,hasTearOffUses:false,getterSelectorId:1] final field self::Model::T? value; | ||
constructor _([@vm.inferred-type.metadata=dart.core::_Smi?] self::Model::T? value) → self::Model<self::Model::T> | ||
: self::Model::value = value, super core::Object::•() | ||
; | ||
static factory •<T extends core::num>() → self::Model<self::Model::•::T> { | ||
core::Object? value = [@vm.direct-call.metadata=dart.core::_IntegerImplementation.==] [@vm.inferred-type.metadata=dart.core::bool (skip check)] [@vm.inferred-type.metadata=int] core::int::parse("1") =={core::num::==}{(core::Object) → core::bool} 1 ?{core::int?} null : 42; | ||
return new self::Model::_<self::Model::•::T>(_in::unsafeCast<self::Model::•::T?>(value)); | ||
} | ||
} | ||
static method main(core::List<core::String> arguments) → void { | ||
final self::Model<core::num> model = [@vm.inferred-type.metadata=#lib::Model<dart.core::num>] self::Model::•<core::num>(); | ||
core::print([@vm.direct-call.metadata=#lib::Model.value] [@vm.inferred-type.metadata=dart.core::_Smi?] model.{self::Model::value}{core::num?}); | ||
core::print([@vm.direct-call.metadata=#lib::Model.value] [@vm.inferred-type.metadata=dart.core::_Smi?] model.{self::Model::value}{core::num?} == null); | ||
} |