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

Implemented stronger type inference for enums and literals #17897

Closed
wants to merge 1 commit into from

Conversation

beef331
Copy link
Collaborator

@beef331 beef331 commented Apr 29, 2021

This PR aims to strenghten the type inference when the type can be resolved from the left hand.
Following is the added features:

type
  A {.pure.} = enum
    left, right, up, down
  B {.pure.} = enum
    left, right, up, down
  Test = object
    case kind: A
    of left:
      a: int
    of {right, down}:
      b: float
    else:
      c: string
  ASet = set[A]

let test = A.left
case test:
of left: discard
of up: discard
else: discard

var
  a: array[4, A] = [left, right, down, up]
  b: array[4, B] = [left, right, down, up]
  c: ASet = {left..right, down, up}
  d: A = left
  e: array[4, byte] = [255, 2, 3, 4]

@Araq
Copy link
Member

Araq commented Apr 30, 2021

This needs an RFC and the implementation looks off-putting. (Which is not your fault, the code follows the existing style, but we have to do better than this, a little type flage here and there, a couple of more edge cases, what could go wrong...)

@beef331
Copy link
Collaborator Author

beef331 commented Apr 30, 2021

Closing with nim-lang/RFCs#373 being made.

@beef331 beef331 closed this Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants