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

[Regression] Compiler crash on proc with static, used to compile in nim 0.16 #5868

Closed
cooldome opened this Issue May 23, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@cooldome
Copy link
Member

cooldome commented May 23, 2017

The minimum reproducible example:

type TaggedType[T; Key: static[string]] = T

proc setKey*[DT](dt: DT, key: static[string]): TaggedType[DT, key] = 
  result = cast[type(result)](dt)

type Students = object
   id : seq[int]
   name : seq[string]
   age: seq[int]

let
  stud = Students(id : @[1,2,3], name : @["Vas", "Pas", "NafNaf"], age : @[10,16,18])
  stud2 = stud.setkey("id")
@zah

This comment has been minimized.

Copy link
Member

zah commented Jun 10, 2017

I'm not sure if this code should be accepted, because with a pure alias Students and TaggedType[Students, X] are the same type (which also creates a cyclic type).

If you add distinct to the type alias, this conundrum will be resolved:

type TaggedType[T; Key: static[string]] = distinct T

proc setKey*[DT](dt: DT, key: static[string]): TaggedType[DT, key] =
  result = cast[type(result)](dt)

type Students = object
   id : seq[int]
   name : seq[string]
   age: seq[int]

let
  stud = Students(id : @[1,2,3], name : @["Vas", "Pas", "NafNaf"], age : @[10,16,18])
  stud2 = stud.setkey("id")

@Araq Araq added this to the v1 milestone Jun 8, 2018

@mratsim

This comment has been minimized.

Copy link
Collaborator

mratsim commented Aug 8, 2018

Works for me. Can probably be closed?

@mratsim

This comment has been minimized.

Copy link
Collaborator

mratsim commented Aug 8, 2018

Actually it doesn't if I had an echo stud2 I receive nothing, so the compiler just quits during compilation.

@Araq Araq closed this in 1428aec Oct 2, 2018

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