fix #31973, dynamic calls to super getters that return Function

Change-Id: I6e87d5a501fcd004b43d570ce8a970ae9b8a5f78
Reviewed-on: https://dart-review.googlesource.com/37900
Reviewed-by: Vijay Menon <vsm@google.com>
Commit-Queue: Jenny Messerly <jmesserly@google.com>
This commit is contained in:
Jenny Messerly 2018-02-01 00:51:06 +00:00 committed by commit-bot@chromium.org
parent 81304281c8
commit 7d60caba63
2 changed files with 31 additions and 7 deletions

View file

@ -3624,7 +3624,9 @@ class CodeGenerator extends Object
}
if (targetType.isDartCoreFunction || targetType.isDynamic) {
// TODO(vsm): Can a call method take generic type parameters?
return _emitDynamicInvoke(node, _visitExpression(target),
return _emitDynamicInvoke(
_visitExpression(target),
_emitInvokeTypeArguments(node),
_emitArgumentList(node.argumentList));
}
}
@ -3707,6 +3709,10 @@ class CodeGenerator extends Object
JS.Expression jsTarget = _emitTarget(target, element, isStatic);
if (isDynamicInvoke(target) || isDynamicInvoke(node.methodName)) {
if (jsTarget is JS.Super) {
jsTarget = _emitTargetAccess(jsTarget, jsName, element);
return _emitDynamicInvoke(jsTarget, typeArgs, args);
}
if (typeArgs != null) {
return _callHelper('#(#, [#], #, #)', [
_emitDynamicOperationName('dgsend'),
@ -3733,9 +3739,8 @@ class CodeGenerator extends Object
return new JS.Call(jsTarget, args);
}
JS.Expression _emitDynamicInvoke(
InvocationExpression node, JS.Expression fn, List<JS.Expression> args) {
var typeArgs = _emitInvokeTypeArguments(node);
JS.Expression _emitDynamicInvoke(JS.Expression fn,
List<JS.Expression> typeArgs, List<JS.Expression> args) {
if (typeArgs != null) {
return _callHelper('dgcall(#, [#], #)', [fn, typeArgs, args]);
} else {
@ -3807,10 +3812,10 @@ class CodeGenerator extends Object
}
var fn = _visitExpression(function);
var args = _emitArgumentList(node.argumentList);
if (isDynamicInvoke(function)) {
return _emitDynamicInvoke(node, fn, args);
}
var typeArgs = _emitInvokeTypeArguments(node);
if (isDynamicInvoke(function)) {
return _emitDynamicInvoke(fn, typeArgs, args);
}
if (typeArgs != null) args.insertAll(0, typeArgs);
return new JS.Call(fn, args);
}

View file

@ -4,6 +4,10 @@
// Regresion test for bug discovered in frog handling super calls: the test case
// mixes generics, super calls, and purposely doesn't allocate the base type.
//
// Also is a regression test for https://github.com/dart-lang/sdk/issues/31973
import 'package:expect/expect.dart';
class C<T> {
foo(T a) {}
@ -15,7 +19,22 @@ class D<T> extends C<T> {
}
}
class A {
static int _value;
Function foo = (int x) => _value = x + 1;
}
class B extends A {
void m(int x) {
super.foo(x);
}
}
main() {
var d = new D();
d.foo(null);
var b = new B();
b.m(41);
Expect.equals(42, A._value);
}