-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CFE does not reject non-const partial instantiations for default parameter values #32912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
With -dev.59, the Dart Analyzer doesn't report any errors for this. /cc @bwilkerson |
@peter-ahe-google to check if this fails in the VM |
Dart2js is rejecting this program, and so is the VM. |
Per triage discussion, and above comment, punting to 2.1 |
I see a runtime error. How can I repro the VM statically rejecting this code? Tried at cc @dgrove - per our discussion regarding breaking changes I think either this or #32913 should be in Dart2Stable. |
FWIW, I see dart2js (which uses the CFE) rejecting this with -dev.67, but I'm not able to see the VM rejecting it statically (I do see a runtime VM error). |
I could have sworn that I saw the VM report this as a compile-time error, but I must have accidentally looked at the output from dart2js. |
Note that dart2js only gives an error on this if the default value is actually used. So the code below is not statically rejected, and gives no errors when run (neither by DDC, nor by dart2js, nor by the VM). dynamic _defaultCallback<T>(T t) => t;
class C<T> {
final dynamic Function(T) callback;
// Should be statically rejected
void foo([dynamic Function(T) f = _defaultCallback]) {}
// Should be statically rejected
const C({this.callback = _defaultCallback});
}
// Should be statically rejected
void bar<T>([dynamic Function(T) f = _defaultCallback]) {}
void main() {
print(new C<int>(callback: _defaultCallback));
} This means that fixing this will be a breaking change. |
Leaf has already reported the behavior on the different implementations in his comment above. |
The Dart analyzer does not catch this. The JIT VM fails if the value is used:
The AOT VM compiler crashes when deserializing a .dill whether or not the value is used:
So we're not really catching this but we're not running it either. I don't know how much it would take to fix the VM's JIT and AOT constant evaluators to catch this. |
/cc @mkustermann |
I've made a CL which would fix it for JIT/AOT VM and give better (though still not very good) error messages. |
…ntiation expression This makes us report the following error * in JIT: Unhandled exception: 'test.dart': error: Type arguments must be instantiated in partial instantiation. #0 main (...) ... * in AOT: test.dart:7:28: Error: The type '#lib1::C::T' is not a constant, only instantiated types are ... const C({this.callback = _defaultCallback}); ^ test.dart:7:17: Context: While analyzing: const C({this.callback = _defaultCallback}); ^ test.dart:5:37: Error: The type '#lib1::C::T' is not a constant, only instantiated types are ... void foo([dynamic Function(T) f = _defaultCallback]) {} ^ test.dart:5:33: Context: While analyzing: void foo([dynamic Function(T) f = _defaultCallback]) {} ^ test.dart:11:38: Error: The type '#lib1::bar::T' is not a constant, only instantiated types are ... void bar<T>([dynamic Function(T) f = _defaultCallback]) {} ^ test.dart:11:34: Context: While analyzing: void bar<T>([dynamic Function(T) f = _defaultCallback]) {} Issue #32912 Change-Id: I05c7019119a50a9cc38939d9cb41aeaa06c853bc Reviewed-on: https://dart-review.googlesource.com/c/81278 Auto-Submit: Martin Kustermann <kustermann@google.com> Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Kevin Millikin <kmillikin@google.com>
This is now caught by the VM in both its JIT and AOT compilers. The remaning work on the front end will be done post-Dart 2.1. |
Closing because there is no more work to do on this except flipping the flag. This will give us a better overview of remaining issues. |
This is the CFE specific issue for the default parameter issue from #32415 .
Partial instantiations of generic methods are only
const
objects if their type arguments areconst
types. The CFE should statically reject the following program, but currently doesn't.The text was updated successfully, but these errors were encountered: