Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Unified Diff: runtime/vm/object.cc

Issue 10280007: Check upper bounds of type arguments when allocating objects of a generic type (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 7209)
+++ runtime/vm/object.cc (working copy)
@@ -2203,8 +2203,8 @@
}
// AbstractType parameters cannot be handled by Class::IsSubtypeOf().
if (IsTypeParameter() || other.IsTypeParameter()) {
- // An uninstantiated type parameter is equivalent to Dynamic.
- return true;
+ return IsTypeParameter() && other.IsTypeParameter() &&
+ (Index() == other.Index());
srdjan 2012/05/01 23:30:51 I do not understand this change.
regis 2012/05/02 01:34:16 The previous test was too lenient. You can imagine
}
const Class& cls = Class::Handle(type_class());
return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()),
@@ -2629,8 +2629,10 @@
}
TypeParameter& other_type_param = TypeParameter::Handle();
other_type_param ^= other.raw();
- // Both type parameters may have different type_class and their index may be
- // different after finalization, which is OK. Do not check.
+ // IsIdentical may be called on type parameters belonging to different
+ // classes, e.g. to an interface and to its default factory class.
+ // Therefore, both type parameters may have different parameterized classes
+ // and different indices. Compare the type parameter names only.
String& name = String::Handle(Name());
String& other_name = String::Handle(other_type_param.Name());
return name.Equals(other_name);
@@ -2959,7 +2961,9 @@
const AbstractTypeArguments& bounds_instantiator,
Error* malformed_error) const {
ASSERT(FLAG_enable_type_checks);
- ASSERT(IsInstantiated());
+ // This function may be called at compile time on (partially) uninstantiated
+ // type arguments and may return true, in which case a run time bounds check
+ // can be avoided.
ASSERT(Length() >= cls.NumTypeArguments());
const intptr_t num_type_params = cls.NumTypeParameters();
const intptr_t offset = cls.NumTypeArguments() - num_type_params;

Powered by Google App Engine
This is Rietveld 408576698