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

Unified Diff: runtime/vm/parser.cc

Issue 134083005: Handle wrong method invocation of a type parameter (fix issue 13134). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 31939)
+++ runtime/vm/parser.cc (working copy)
@@ -8416,19 +8416,27 @@
AstNode* array = left;
if (left->IsPrimaryNode()) {
PrimaryNode* primary = left->AsPrimaryNode();
+ const intptr_t primary_pos = primary->token_pos();
if (primary->primary().IsFunction()) {
array = LoadClosure(primary);
} else if (primary->primary().IsClass()) {
const Class& type_class = Class::Cast(primary->primary());
AbstractType& type = Type::ZoneHandle(
Type::New(type_class, TypeArguments::Handle(),
- primary->token_pos(), Heap::kOld));
+ primary_pos, Heap::kOld));
type ^= ClassFinalizer::FinalizeType(
current_class(), type, ClassFinalizer::kCanonicalize);
// Type may be malbounded, but not malformed.
ASSERT(!type.IsMalformed());
- array = new TypeNode(primary->token_pos(), type);
+ array = new TypeNode(primary_pos, type);
} else if (primary->primary().IsTypeParameter()) {
+ if (current_function().is_static()) {
+ const String& name = String::ZoneHandle(
+ TypeParameter::Cast(primary->primary()).name());
+ ErrorMsg(primary_pos,
hausner 2014/01/18 00:29:55 I think you can factor this out. It is an error wi
regis 2014/01/18 00:48:53 I added the check for T.id, but I did not factor o
+ "cannot access type parameter '%s' from static function",
+ name.ToCString());
+ }
if (current_block_->scope->function_level() > 0) {
// Make sure that the instantiator is captured.
CaptureInstantiator();
@@ -8439,7 +8447,7 @@
TypeParameter::Cast(primary->primary()),
ClassFinalizer::kCanonicalize);
ASSERT(!type_parameter.IsMalformed());
- array = new TypeNode(primary->token_pos(), type_parameter);
+ array = new TypeNode(primary_pos, type_parameter);
} else {
UNREACHABLE(); // Internal parser error.
}
@@ -8472,11 +8480,11 @@
} else if (primary->primary().IsString()) {
// Primary is an unresolved name.
if (primary->IsSuper()) {
- ErrorMsg(primary->token_pos(), "illegal use of super");
+ ErrorMsg(primary_pos, "illegal use of super");
}
String& name = String::CheckedZoneHandle(primary->primary().raw());
if (current_function().is_static()) {
- selector = ThrowNoSuchMethodError(primary->token_pos(),
+ selector = ThrowNoSuchMethodError(primary_pos,
current_class(),
name,
NULL, // No arguments.
@@ -8485,30 +8493,29 @@
NULL); // No existing function.
} else {
// Treat as call to unresolved (instance) method.
- AstNode* receiver = LoadReceiver(primary->token_pos());
- selector = ParseInstanceCall(receiver, name);
+ selector = ParseInstanceCall(LoadReceiver(primary_pos), name);
}
} else if (primary->primary().IsTypeParameter()) {
- // TODO(regis): Issue 13134. Make sure the error message is the
- // one we want here and add a test covering this code.
const String& name = String::ZoneHandle(
TypeParameter::Cast(primary->primary()).name());
- selector = ThrowNoSuchMethodError(primary->token_pos(),
- current_class(),
- name,
- NULL, // No arguments.
- InvocationMirror::kStatic,
- InvocationMirror::kMethod,
- NULL); // No existing function.
+ if (current_function().is_static()) {
+ // Treat as this.T(), because T is in scope.
+ ErrorMsg(primary_pos,
+ "cannot access type parameter '%s' from static function",
+ name.ToCString());
+ } else {
+ // Treat as call to unresolved (instance) method.
+ selector = ParseInstanceCall(LoadReceiver(primary_pos), name);
+ }
} else if (primary->primary().IsClass()) {
const Class& type_class = Class::Cast(primary->primary());
AbstractType& type = Type::ZoneHandle(Type::New(
- type_class, TypeArguments::Handle(), primary->token_pos()));
+ type_class, TypeArguments::Handle(), primary_pos));
type ^= ClassFinalizer::FinalizeType(
current_class(), type, ClassFinalizer::kCanonicalize);
// Type may be malbounded, but not malformed.
ASSERT(!type.IsMalformed());
- selector = new TypeNode(primary->token_pos(), type);
+ selector = new TypeNode(primary_pos, type);
} else {
UNREACHABLE(); // Internal parser error.
}
@@ -8522,19 +8529,27 @@
left = LoadFieldIfUnresolved(left);
if (left->IsPrimaryNode()) {
PrimaryNode* primary = left->AsPrimaryNode();
+ const intptr_t primary_pos = primary->token_pos();
if (primary->primary().IsFunction()) {
// Treat as implicit closure.
left = LoadClosure(primary);
} else if (primary->primary().IsClass()) {
const Class& type_class = Class::Cast(primary->primary());
AbstractType& type = Type::ZoneHandle(Type::New(
- type_class, TypeArguments::Handle(), primary->token_pos()));
+ type_class, TypeArguments::Handle(), primary_pos));
type = ClassFinalizer::FinalizeType(
current_class(), type, ClassFinalizer::kCanonicalize);
// Type may be malbounded, but not malformed.
ASSERT(!type.IsMalformed());
- left = new TypeNode(primary->token_pos(), type);
+ left = new TypeNode(primary_pos, type);
} else if (primary->primary().IsTypeParameter()) {
+ if (current_function().is_static()) {
+ const String& name = String::ZoneHandle(
+ TypeParameter::Cast(primary->primary()).name());
+ ErrorMsg(primary_pos,
+ "cannot access type parameter '%s' from static function",
+ name.ToCString());
+ }
if (current_block_->scope->function_level() > 0) {
// Make sure that the instantiator is captured.
CaptureInstantiator();
@@ -8545,7 +8560,7 @@
TypeParameter::Cast(primary->primary()),
ClassFinalizer::kCanonicalize);
ASSERT(!type_parameter.IsMalformed());
- left = new TypeNode(primary->token_pos(), type_parameter);
+ left = new TypeNode(primary_pos, type_parameter);
} else if (primary->IsSuper()) {
// Return "super" to handle unary super operator calls,
// or to report illegal use of "super" otherwise.
@@ -9229,6 +9244,7 @@
}
if (resolved->IsPrimaryNode()) {
PrimaryNode* primary = resolved->AsPrimaryNode();
+ const intptr_t primary_pos = primary->token_pos();
if (primary->primary().IsString()) {
// We got an unresolved name. If we are compiling a static
// method, evaluation of an unresolved identifier causes a
@@ -9257,12 +9273,12 @@
} else if (primary->primary().IsClass()) {
const Class& type_class = Class::Cast(primary->primary());
AbstractType& type = Type::ZoneHandle(
- Type::New(type_class, TypeArguments::Handle(), primary->token_pos()));
+ Type::New(type_class, TypeArguments::Handle(), primary_pos));
type ^= ClassFinalizer::FinalizeType(
current_class(), type, ClassFinalizer::kCanonicalize);
// Type may be malbounded, but not malformed.
ASSERT(!type.IsMalformed());
- resolved = new TypeNode(primary->token_pos(), type);
+ resolved = new TypeNode(primary_pos, type);
}
}
return resolved;
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | tests/language/type_variable_conflict2_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698