Skip to content

Allow fine grain control over checked-mode behavior in production and development #18138

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

Closed
DartBot opened this issue Apr 10, 2014 · 5 comments
Closed
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Apr 10, 2014

This issue was originally filed by [email protected]


I'm writing a framework that does RPC. Something like this:

someRpcFunction(Foo f, Bar b) { ... }

exportForRpc(someRpcFunction);

The framework calls the function is using Function.apply() after deserializing the arguments.

Dart will check the parameter types, but only in checked mode. This gives a false sense of security. To get the same checking in production mode, you have to check the types again:

rpcFunction(Foo f, Bar b) {
  if (!(f is Foo) || !(b is Bar)) {
    throw "function called with bad arguments";
  }
}

This is redundant and makes it easy to make mistakes.

So, it would be nice if there were a @­checked annotation to keep argument type-checking on all the time for a particular function, and a way to test whether a given function is @­checked. Then the framework can ensure that all functions exported for RPC have their arguments checked all the time.

@lrhn
Copy link
Member

lrhn commented Apr 10, 2014

Added Type-Enhancement, Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Apr 11, 2014

This comment was originally written by [email protected]


A second use case would be deserialization:

class Foo {
  num a;
  String b;
  Foo(this.a, this.b);

  factory Foo.fromJson(Map data) {
    return new Foo(data["a"], data["b"]);
  }
}

If "a" and "b" are swapped, nothing checks the types in production mode, so the user will have to write redundant checking code. A @­checked annotation on the constructor would fix this.

@DartBot
Copy link
Author

DartBot commented Apr 18, 2014

This comment was originally written by @Emasoft


I agree. Also it should be possible to FORCE type checking even at runtime when Dart is run natively in Dartium.

@gbracha
Copy link
Contributor

gbracha commented Aug 26, 2014

I think it would be very nice to have more fine grain control over checked mode - both to turn it on and to turn it off. I'm not fond of using annotations for semantic effects - this is a slippery slope. I'm changing the summary to avoid overspecifying a solution.


Set owner to @gbracha.
Added Accepted label.
Changed the title to: "Allow fine grain control over checked-mode behavior in production and development".

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 26, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@munificent
Copy link
Member

Strong mode does do this checking. When the VM and dart2js fully support strong mode at runtime, that will address this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants