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

Enable 'as' and 'is' syntax for types available only at runtime #945

Open
jonaird opened this issue Apr 29, 2020 · 1 comment
Open

Enable 'as' and 'is' syntax for types available only at runtime #945

jonaird opened this issue Apr 29, 2020 · 1 comment
Labels
feature Proposed language feature that solves one or more problems

Comments

@jonaird
Copy link

jonaird commented Apr 29, 2020

There may be some obscure reason that this is not a good idea or even possible but it would be nice to be able to do the following:

var string = 'hello';
var int = 1;
print(int is string.runtimeType);

Or be able to save a type in a variable and use it later:

var string = 'hello';
var int = 1;
var aType = string.runtimeType;
print(int is aType);

This produces a pretty silly error:
Error: 'aType' isn't a type.

Is there a difference between types and the type class?

@jonaird jonaird added the feature Proposed language feature that solves one or more problems label Apr 29, 2020
@mraleph
Copy link
Member

mraleph commented Apr 29, 2020

This has been considered before in various forms (e.g. as an extension to Type API dart-lang/sdk#30717 or as permitting expressions on the right hand side of is).

In general the only argument against this is based on the estimated code size impact, because compiler looses a good way to estimate which type checks can occur in the program - and thus can no longer throw away some of the metadata associated with the class hierarchy. @rakudrama has done experiment for dart2js to estimate approximate impact and saw some non negligible costs in terms of the code size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants