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

Unified Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2560983002: Support callable classes where call is inherited (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | pkg/dev_compiler/test/codegen/language/callable_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dev_compiler/lib/src/compiler/code_generator.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/code_generator.dart b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
index 3bd756da70c9e9cb7d42767af9f5a90dba996aa7..b2f28d02be128a17d755fde38a578af25902e6ff 100644
--- a/pkg/dev_compiler/lib/src/compiler/code_generator.dart
+++ b/pkg/dev_compiler/lib/src/compiler/code_generator.dart
@@ -752,7 +752,8 @@ class CodeGenerator extends GeneralizingAstVisitor
var staticFields = <FieldDeclaration>[];
var methods = <MethodDeclaration>[];
- // True if a "call" method or getter exists.
+ // True if a "call" method or getter exists directly on this class.
+ // If so, we need to install a Function prototype.
bool isCallable = false;
for (var member in node.members) {
if (member is ConstructorDeclaration) {
@@ -780,6 +781,16 @@ class CodeGenerator extends GeneralizingAstVisitor
}
}
+ // True if a "call" method or getter exists directly or indirectly on this
+ // class. If so, we need special constructor handling.
+ bool isCallableTransitive =
+ classElem.lookUpMethod('call', currentLibrary) != null;
+ if (!isCallableTransitive) {
+ var callGetter = classElem.lookUpGetter('call', currentLibrary);
+ isCallableTransitive =
+ callGetter != null && callGetter.returnType is FunctionType;
+ }
+
JS.Expression className;
if (classElem.typeParameters.isNotEmpty) {
// Generic classes will be defined inside a function that closes over the
@@ -816,7 +827,7 @@ class CodeGenerator extends GeneralizingAstVisitor
_emitClassTypeTests(classElem, className, body);
- _defineNamedConstructors(ctors, body, className, isCallable);
+ _defineNamedConstructors(ctors, body, className, isCallableTransitive);
body.addAll(virtualFieldSymbols);
_emitClassSignature(
methods, allFields, classElem, ctors, extensions, className, body);
« no previous file with comments | « no previous file | pkg/dev_compiler/test/codegen/language/callable_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698