Skip to content
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

VM should provide more actionable details for typedef mismatch #5740

Closed
sethladd opened this issue Oct 9, 2012 · 8 comments
Closed

VM should provide more actionable details for typedef mismatch #5740

sethladd opened this issue Oct 9, 2012 · 8 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug

Comments

@sethladd
Copy link
Contributor

sethladd commented Oct 9, 2012

For an error such as:

Exception: type '(int) => void' is not a subtype of type 'RequestAnimationFrameCallback' of 'callback'.
Stack Trace: #­0 _DOMWindowImpl.requestAnimationFrame (/Volumes/data/b/build/slave/dartium-mac-full/build/src/xcodebuild/DerivedSources/Release/webkit/bindings/dart/dart/WindowImpl.dart:190:59)

­1 SolarSystem.requestRedraw (http://127.0.0.1:3030/Users/sethladd/Code/Dart/dart/samples/solar/solar.dart:145:33)

­2 SolarSystem._start (http://127.0.0.1:3030/Users/sethladd/Code/Dart/dart/samples/solar/solar.dart:111:18)

­3 SolarSystem.start.<anonymous closure> (http://127.0.0.1:3030/Users/sethladd/Code/Dart/dart/samples/solar/solar.dart:72:13)

­4 FutureImpl._complete (bootstrap_impl:605:19)

­5 FutureImpl._complete (bootstrap_impl:613:5)

­6 FutureImpl._setValue (bootstrap_impl:627:14)

­7 CompleterImpl.complete (bootstrap_impl:710:26)

­8 _completeMeasurementFutures._completeMeasurementFutures (/Volumes/data/b/build/slave/dartium-mac-full/build/src/dart/lib/html/src/Measurement.dart:115:35)

­9 _MeasurementScheduler._onCallback (/Volumes/data/b/build/slave/dartium-mac-full/build/src/dart/lib/html/src/Measurement.dart:34:19)

­10 _MutationObserverScheduler._handleMutation._handleMutation (/Volumes/data/b/build/slave/dartium-mac-full/build/src/dart/lib/html/src/Measurement.dart:63:21)

It would be very nice if the error message also reported what RequestAnimationFrameCallback's signature is. The current message doesn't tell me how to fix the problem.

Also, the "of 'callback'" isn't clear.

@DartBot
Copy link

DartBot commented Oct 27, 2012

This comment was originally written by shalmak...@gmail.com


It seems to me that there are 2 additional issues here -
1 - an instance method receiving an int and returning void doesn't match RequestAnimationFrameCallback (presumably because of the hidden "this" argument?). I guessed that this is why the above is failing and successfully worked around it with another method like this:
  RequestAnimationFrameCallback callback_maker()
  {
    return (int time) { my_method(time); };
  }

// ...
      RequestAnimationFrameCallback c = callback_maker();
    window.requestAnimationFrame(c);

2 - the error message doesn't accurately describe the problem because type '(int) => void' IS in fact identical to RequestAnimationFrameCallback. If it would say '(myobject, int) => void' is not a subtype etc. then I would understand why it is failing.

I don't know whether #­1 would be considered a defect or a desirable behavior. I would either expect methods to be acceptable as callbacks with "this" being passed implicitly, or alternately I would expect an error message that would explicitly show the problematic "this" argument.

@iposva-google
Copy link
Contributor

Removed Priority-Medium label.
Added Priority-Unassigned label.

@DartBot
Copy link

DartBot commented Sep 20, 2013

This comment was originally written by @mhausner


Would be nice to have a simpler, standalone example that reproduces the situation.


Removed Type-Defect label.
Added Type-Enhancement label.

@sethladd
Copy link
Contributor Author

My pleasure. Here's an app:

typedef bool DoThing(int x);

run(DoThing callback) {
  callback(1);
}

main() {
  run(() => print('this will fail at runtime'));
}

Run it this way:

sethladd:~/tmp$ dart --checked typedef.dart

Get this error:

Unhandled exception:
type '() => dynamic' is not a subtype of type 'DoThing' of 'callback'.
#­0 run (file:///Users/sethladd/tmp/typedef.dart:3:13)
#­1 main (file:///Users/sethladd/tmp/typedef.dart:8:6)

Suggestion:

Can we print out what the signature of DoThing is? Maybe:

type '() => dynamic' is not a subtype of type '(int) => bool' of 'callback'.

Thanks for taking a look.

@DartBot
Copy link

DartBot commented Sep 21, 2013

This comment was originally written by @mhausner


Thank you for the simple repro case!


Set owner to @mhausner.
Added Accepted label.

@iposva-google
Copy link
Contributor

I am still puzzled as to what we are supposed to fix here. DoThing takes an int parameter, it is being assigned a value that takes no parameter. Mismatch, checked mode failure, all is well.

The one thing that could be worded better is the "of 'callback'."


cc @gbracha.

@sethladd
Copy link
Contributor Author

Hi Ivan,

Can we tell the user what the signature of DoThing is? That would be really helpful. And yes, "of callback" isn't very clear.

@sethladd sethladd added Type-Enhancement area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Sep 21, 2013
@iposva-google
Copy link
Contributor

dart ~/dart/Bug5740.dart
Unhandled exception:
Closure call with mismatched arguments: function 'main.'

NoSuchMethodError: incorrect number of arguments passed to method named 'main.'
Receiver: Closure: () => dynamic
Tried calling: main.(1)
Found: main.()
#0 Object._noSuchMethod (dart:core-patch/object_patch.dart:42)
#1 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#2 run (file:///Users/iposva/dart/Bug5740.dart:4:11)
#3 main (file:///Users/iposva/dart/Bug5740.dart:8:3)
#4 _startIsolate. (dart:isolate-patch/isolate_patch.dart:261)
#5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)

@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants