sdk
sdk copied to clipboard
Expression evaluation returns an error when trying to use extension inside aliased import
Repro:
Files
main.dart:
import 'ext.dart' as ext;
import 'ext2.dart';
void main() {
final i = 0;
print(i.foo());
print(i.bar());
print(i.baz());
}
extension E2 on int {
int bar() => this;
}
ext.dart
extension E on int {
int foo() => this;
}
ext2.dart
extension E3 on int {
int baz() => this;
}
Place a breakpoint under main.dart at any line and add all of these to watch:
i.foo()i.bar()i.baz()
Even with the code running and the analyzer saying nothing, the expression evaluation for i.foo() which is under import 'ext.dart' as ext; throws an error.
Related: https://github.com/dart-lang/sdk/issues/56555
CC: @DanTup
Summary: Expression evaluation fails when attempting to use an extension method imported with an alias, even though the analyzer does not report any errors. This issue occurs when the extension method is defined in a separate file and imported with an alias.
I believe this issue is in the same area as https://github.com/dart-lang/sdk/issues/56555, marking this as a duplicate of that issue.
My point in making them separate was so that this one focuses on solving the error and the other one focuses on the error message. But if you believe that they should be handled together thats alright by me.
Unless the reason #56555 shows _Smi as the type name is because of the extension/aliased import, these seem like different issues to me. My understanding is:
- this issue is about not being able to evaluate expressions using extension members if they
imported with an alias - that issue is about the message saying "isn't defined for the class
_Smi" but it's not clear what_Smiis one might have expected to seeinthere
@johnniwinther, It seems like frontend changes are needed to fix this. I inspected the arguments passed to KernelIsolate::CompileExpressionToKernel here once when running the reproduction example as written, and again after changing the import 'ext.dart' as ext; line to just import 'ext.dart';. The arguments passed were the same in both cases, the interesting ones being: expression: "i.foo()", params: ["i"], param_types: ["dart:core", "_Smi", "1", "0"], but compilation fails when the prefix is used to import 'ext.dart' and succeeds when the prefix isn't used. Please let me know if any VM changes are required.