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

typedesc as array members are still allowed #12398

Closed
dawkot opened this issue Oct 9, 2019 · 9 comments
Closed

typedesc as array members are still allowed #12398

dawkot opened this issue Oct 9, 2019 · 9 comments

Comments

@dawkot
Copy link

dawkot commented Oct 9, 2019

Example

var xs = [int, float, string]

Error

Error: internal error: symbol has no generated name: int

Example

const xs = [int, float, string]

echo xs[0]
echo xs[1]
echo xs[2]

Output

None
None
None

Expected output

Neither should compile (?)

@ghost ghost added the Compiler Crash label Oct 9, 2019
@krux02 krux02 changed the title [warning: super low priority] Some typedesc array weirdness typedesc as array members are still allowed Oct 11, 2019
@krux02
Copy link
Contributor

krux02 commented Oct 11, 2019

This is strage, because I have memories implementing a compiler check to prevent exactly this. False memories? Anyway, these issue are related.

#8654
#8610

This PR is related:
#11959

@ghost
Copy link

ghost commented Jun 24, 2020

Shows a proper error on latest devel:

~/P/ircord ❯❯❯ nim c -r "/home/dian/Projects/ircord/a.nim"
Hint: used config file '/home/dian/Things/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/dian/Things/Nim/config/config.nims' [Conf]
Hint: used config file '/home/dian/nim.cfg' [Conf]
....
/home/dian/Projects/ircord/a.nim(1, 5) Error: invalid type: 'typedesc' in this context: 'array[0..2, typedesc]' for var

Do we have a test case for that?

@timotheecour
Copy link
Member

@timotheecour
Copy link
Member

closed by #14795

@kamilchm
Copy link

Is there a way to have some sort of list of typedescs in a static block?

@Araq
Copy link
Member

Araq commented Apr 27, 2021

You can do type introspection via Nim's macro system.

@timotheecour
Copy link
Member

Is there a way to have some sort of list of typedescs in a static block?

type A = (int, float) ?

@kamilchm
Copy link

kamilchm commented Apr 27, 2021

I was looking for something to use a list of types in a loop, eg.:

macro x(t: typedesc) =
  ...

static:
  for t in [MyType1, MyType2, ....]: # <- I want to use it here
    x(t)

@tsoj
Copy link

tsoj commented Aug 7, 2021

I was looking for something to use a list of types in a loop, eg.:

macro x(t: typedesc) =
  ...

static:
  for t in [MyType1, MyType2, ....]: # <- I want to use it here
    x(t)

In this specific example, you could probably use a macro xMany(args: varargs[untyped]), where each args[i] is a type. But something like openArray[T1, T2, T3] would still be really helpful in cases, where one wouldn't want to use a macro (or a template), but a proper function.
Though I currently can't think of an example other than an entity component system, if I'm honest.

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

6 participants