Skip to content

dart2js attributes the wrong type to super tearoffs #40902

@fishythefish

Description

@fishythefish

The following code incorrectly prints true instead of false.

class Foo {
  int f() => 42;
}

class Bar extends Foo {
  void test() {
    var f = super.f;
    print(f is int);
  }
}

void main() {
  Bar().test();
}

We build an HInvokeSuper node for the super.f access here:

_buildInvokeSuper(
_elementMap.getSelector(node),
_elementMap.getClass(_containingClass(node)),
member,
const <HInstruction>[],
const <DartType>[],
sourceInformation);
}

The problem is that this is indistinguishable from the node we would have built for the method invocation super.f():
_buildInvokeSuper(
_elementMap.getSelector(node),
_elementMap.getClass(_containingClass(node)),
member,
arguments,
typeArguments,
sourceInformation);
}

When we build the node, we attempt to determine the type by inspecting the member:

if (target is FunctionEntity) {
typeMask = _typeInferenceMap.getReturnTypeOf(target);
} else {
typeMask = _abstractValueDomain.dynamicType;
}

Of course, in both super.f and super.f(), the member is the same FunctionEntity, but only in the latter case does it make sense to use the return type.

Metadata

Metadata

Assignees

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2js

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions