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

type behaves as the identity operator when applied to types #1674

Open
MasonMcGill opened this issue Nov 25, 2014 · 4 comments
Open

type behaves as the identity operator when applied to types #1674

MasonMcGill opened this issue Nov 25, 2014 · 4 comments

Comments

@MasonMcGill
Copy link

Currently, type(int) is int. I expect type(int) should either

  1. be typedesc.
  2. result in a compile-time error.

Types other than int behave analogously.

@zah
Copy link
Member

zah commented Jan 5, 2015

Can you provide some more context? In which situations is type(int) treated as int?

type should act as the identity operators only when applied to typedescs (which may be surprising to some purists expecting even higher-orders types-of-types).

@MasonMcGill
Copy link
Author

@zah: Interestingly, the main issue I was having (f(x: int) and f(x: typedesc[int]) being confused during overload resolution) seems to have been fixed in the last release or two.

Though the following program still compiles (and it shouldn't):

static:
  assert int is type(int)
  assert type(int) is int

@timotheecour
Copy link
Member

see also test case here:

@krux02
Copy link
Contributor

krux02 commented Aug 19, 2019

Because it is unclear if type(x) means typedesc[x] or typeof(x) the short syntax is discouraged to use. A deprecation message is not emitted yet though. But type(int) is certainly not the identity operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants