dart-lang / dart-lang/language

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

Open
#945 1 comment 4 reactions 0 assignees View on GitHub
feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

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](https://api.dart.dev/stable/2.8.0/dart-core/Type-class.html)?

Contributor guide

Open the contributing guide

Research direction

Start with the issue's runtimeType examples and the linked dart:core Type-class documentation. Investigate how Dart distinguishes compile-time types from Type values in `is` and `as` expressions, and determine the intended semantics for using a runtime type variable. Done means a documented language-design decision or proposal that resolves the requested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.