Fix wrong canonicalization of signature class due to name collision (issue 6353).

Add test.
Review URL: https://codereview.chromium.org//11342028

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14234 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
regis@google.com 2012-10-30 00:06:24 +00:00
parent d4c5f9f05b
commit 57a60316f0
4 changed files with 38 additions and 11 deletions

View file

@ -3921,14 +3921,15 @@ RawString* Function::BuildSignature(
const String& kCommaSpace = String::Handle(Symbols::New(", "));
const String& kColonSpace = String::Handle(Symbols::New(": "));
const String& kLParen = String::Handle(Symbols::New("("));
const String& kRParen = String::Handle(Symbols::New(") => "));
const String& kRParenArrow = String::Handle(Symbols::New(") => "));
const String& kLBracket = String::Handle(Symbols::New("["));
const String& kRBracket = String::Handle(Symbols::New("]"));
const String& kLBrace = String::Handle(Symbols::New("{"));
const String& kRBrace = String::Handle(Symbols::New("}"));
String& name = String::Handle();
if (!instantiate && !is_static()) {
// Prefix the signature with its type parameters, if any (e.g. "<K, V>").
if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
// Prefix the signature with its class and type parameters, if any (e.g.
// "Map<K, V>(K) => bool").
// The signature of static functions cannot be type parameterized.
const String& kSpaceExtendsSpace =
String::Handle(Symbols::New(" extends "));
@ -3939,6 +3940,8 @@ RawString* Function::BuildSignature(
const TypeArguments& type_parameters = TypeArguments::Handle(
function_class.type_parameters());
if (!type_parameters.IsNull()) {
const String& function_class_name = String::Handle(function_class.Name());
pieces.Add(function_class_name);
intptr_t num_type_parameters = type_parameters.Length();
pieces.Add(kLAngleBracket);
TypeParameter& type_parameter = TypeParameter::Handle();
@ -3948,7 +3951,7 @@ RawString* Function::BuildSignature(
name = type_parameter.name();
pieces.Add(name);
bound = type_parameter.bound();
if (!bound.IsNull() && !bound.IsDynamicType()) {
if (!bound.IsNull() && !bound.IsObjectType()) {
pieces.Add(kSpaceExtendsSpace);
name = bound.BuildName(name_visibility);
pieces.Add(name);
@ -4011,7 +4014,7 @@ RawString* Function::BuildSignature(
pieces.Add(kRBrace);
}
}
pieces.Add(kRParen);
pieces.Add(kRParenArrow);
AbstractType& res_type = AbstractType::Handle(result_type());
if (instantiate && !res_type.IsInstantiated()) {
res_type = res_type.InstantiateFrom(instantiator);

View file

@ -1061,17 +1061,18 @@ class Function : public Object {
RawString* QualifiedUserVisibleName() const;
virtual RawString* DictionaryName() const { return name(); }
// Build a string of the form '<T, R>(T, [b: B, c: C]) => R' representing the
// internal signature of the given function.
// Build a string of the form 'C<T, R>(T, {b: B, c: C}) => R' representing the
// internal signature of the given function. In this example, T and R are
// type parameters of class C, the owner of the function.
RawString* Signature() const {
const bool instantiate = false;
return BuildSignature(instantiate, kInternalName, TypeArguments::Handle());
}
// Build a string of the form '(A, [b: B, c: C]) => D' representing the
// Build a string of the form '(A, {b: B, c: C}) => D' representing the
// signature of the given function, where all generic types (e.g. '<T, R>' in
// '<T, R>(T, [b: B, c: C]) => R') are instantiated using the given
// instantiator type argument vector (e.g. '<A, D>').
// 'C<T, R>(T, {b: B, c: C}) => R') are instantiated using the given
// instantiator type argument vector of a C instance (e.g. '<A, D>').
RawString* InstantiatedSignatureFrom(
const AbstractTypeArguments& instantiator,
NameVisibility name_visibility) const {

View file

@ -1031,7 +1031,7 @@ class RawTypeParameter : public RawAbstractType {
}
RawClass* parameterized_class_;
RawString* name_;
RawAbstractType* bound_; // DynamicType if no explicit bound specified.
RawAbstractType* bound_; // ObjectType if no explicit bound specified.
RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->bound_); }
intptr_t index_;
intptr_t token_pos_;

View file

@ -0,0 +1,23 @@
// Copyright (c) 2011, 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 issue 6353.
class A<E> {
}
class C<E> extends A<E> {
forEach(callback(E element)) {
}
}
class D<E> {
lala(E element) {
}
}
main() {
var c = new C<int>();
c.forEach(new D<int>().lala);
}