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

nested static enums type require forward declaration in the same type section #16394

Open
mratsim opened this issue Dec 18, 2020 · 0 comments
Open

Comments

@mratsim
Copy link
Collaborator

mratsim commented Dec 18, 2020

The following doesn't compile and will throw Error: type expected

type
  TrustLevel* = enum
    Unchecked
    SigVerified
    TransitionVerified
    Trusted

  # Trust level aliases
  TrustedSignedBeaconBlock* = SignedBeaconBlock[Trusted]
  UntrustedSignedBeaconBlock* = SignedBeaconBlock[Unchecked] or
                                SignedBeaconBlock[SigVerified] or
                                SignedBeaconBlock[TransitionVerified]
  TrustedBeaconBlock* = BeaconBlock[Trusted]
  UntrustedBeaconBlock* = BeaconBlock[Unchecked] or
                          BeaconBlock[SigVerified] or
                          BeaconBlock[TransitionVerified]

  ValidatorSig = object
    data: array[48, byte]

  TrustedSig = object
    data: array[48, byte]

  BeaconBlock*[Trust: static TrustLevel] = object
    body*: BeaconBlockBody[Trust]

  BeaconBlockBody*[Trust: static TrustLevel] = object
    when Trust in {SigVerified, Trusted}:
      randao_reveal*: TrustedSig
    else:
      randao_reveal*: ValidatorSig
    randao_reveal*: ValidatorSig

  SignedBeaconBlock*[Trust: static TrustLevel] = object
    message*: BeaconBlock[Trust]
    when Trust in {SigVerified, Trusted}:
      signature*: TrustedSig
    else:
      signature*: ValidatorSig

The following with everything reordered to be forward declared compiles:

type
  TrustLevel* = enum
    Unchecked
    SigVerified
    TransitionVerified
    Trusted

  ValidatorSig = object
    data: array[48, byte]

  TrustedSig = object
    data: array[48, byte]


  BeaconBlockBody*[Trust: static TrustLevel] = object
    when Trust in {SigVerified, Trusted}:
      randao_reveal*: TrustedSig
    else:
      randao_reveal*: ValidatorSig
    randao_reveal*: ValidatorSig

  BeaconBlock*[Trust: static TrustLevel] = object
    body*: BeaconBlockBody[Trust]

  SignedBeaconBlock*[Trust: static TrustLevel] = object
    message*: BeaconBlock[Trust]
    when Trust in {SigVerified, Trusted}:
      signature*: TrustedSig
    else:
      signature*: ValidatorSig


  # Trust level aliases
  TrustedSignedBeaconBlock* = SignedBeaconBlock[Trusted]
  UntrustedSignedBeaconBlock* = SignedBeaconBlock[Unchecked] or
                                SignedBeaconBlock[SigVerified] or
                                SignedBeaconBlock[TransitionVerified]
  TrustedBeaconBlock* = BeaconBlock[Trusted]
  UntrustedBeaconBlock* = BeaconBlock[Unchecked] or
                          BeaconBlock[SigVerified] or
                          BeaconBlock[TransitionVerified]
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

1 participant