[vm/nnbd] Fix TypeArguments::IsUninstantiatedIdentity for NNBD

TypeArguments::IsUninstantiatedIdentity predicate is checking if
instantiator type arguments could be reused when instantiating
given type arguments (when given type arguments repeat type parameters).
This predicate was not accounting for nullable and legacy type
parameters which could change nullability of types when instantiated.

For example:

  class A<T> {}

1. instantiator type arguments [int], instantiating A<T?> results in
   [int?] type arguments vector, so instantiator type arguments should
   not be reused.

2. instantiator type arguments [int], instantiating A<T*> results in
   [int*] type arguments vector so instantiator type arguments should
   not be reused.

Change-Id: I1e041486829e8ac0cfd3ce59d0ec5164a0f3724c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136709
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
This commit is contained in:
Alexander Markov 2020-02-20 23:39:46 +00:00 committed by commit-bot@chromium.org
parent 2a42699761
commit 1ec87d1770

View file

@ -5875,12 +5875,10 @@ bool TypeArguments::IsUninstantiatedIdentity() const {
if ((type_param.index() != i) || type_param.IsFunctionTypeParameter()) {
return false;
}
// If this type parameter specifies an upper bound, then the type argument
// vector does not really represent the identity vector. It cannot be
// substituted by the instantiator's type argument vector without checking
// the upper bound.
const AbstractType& bound = AbstractType::Handle(type_param.bound());
if (!bound.IsObjectType() && !bound.IsDynamicType()) {
// Instantiating nullable and legacy type parameters may change
// nullability of a type, so type arguments vector containing such type
// parameters cannot be substituted with instantiator type arguments.
if (type_param.IsNullable() || type_param.IsLegacy()) {
return false;
}
}