Skip to content

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

Closed
@DartBot

Description

@DartBot

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.

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions